本文介绍了git update-index --assume-unchanged 在目录上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git 1.7.12

我想将给定目录下的所有文件标记为假定未更改.

I want to mark all files below a given directory as assume-unchanged.

  1. git update-index --assume-unchanged dir/ 给出忽略路径".

git update-index --assume-unchanged dir/* 很快就会失败,因为它会遇到未被跟踪的文件,因此它给出了致命:无法标记文件"并退出.

git update-index --assume-unchanged dir/* quickly fails because it will encounter files which are not being tracked, hence it gives "fatal: Unable to mark file" and quits.

尝试生成要标记的文件列表.cd 进入所需目录,然后运行 ​​git ls-files |tr '' ' ' |git update-index --assume-unchanged.这不会产生错误消息,但不会成功标记文件.命令的第一部分,git ls-files |tr '' ' ',正确生成我想要标记的所有文件的空格分隔列表.如果我将该命令的输出复制并粘贴到命令行,则 git update-index 命令将起作用.什么不适用于管道?

Try generating a list of files to mark. cd into the desired directory and then run git ls-files | tr '' ' ' | git update-index --assume-unchanged. This produces no error message, but it does not successfully mark the files. The first portion of the command, git ls-files | tr '' ' ', correctly produces a space delimited list of all the files I want to mark. If I copy and paste the output of that command onto the command-line, then the git update-index command works. What is not working with the pipes?

不,将 dir 添加到 .gitignore 对我来说是不够的.我需要将这些文件放在存储库中,但会在本地进行不需要的更改,需要忽略这些更改,以便用户可以执行拉取操作.

No, it is not sufficient for me to add dir to .gitignore. I need these files to be in the repository, but undesired changes will be made locally that need to be ignored so that users can do pulls.

推荐答案

git update-index 希望文件名在其命令行上,而不是在其标准输入上.

git update-index wants the file names on its command line, not on its standard input.

cd 进入您要假设未更改的文件夹

cd into the folder you want to assume is unchanged

你可以这样做:

git update-index --assume-unchanged $(git ls-files | tr '
' ' ')

git ls-files | tr '
' ' ' | xargs git update-index --assume-unchanged

尽管在任何一种情况下,带有空格的文件名都会有问题.如果你有这些,你可以使用这个:

Although, with either case, file names with spaces will be problematic. If you have those, you can use this:

git ls-files -z | xargs -0 git update-index --assume-unchanged

合并来自@MatthewScharley 的关于 git ls-files -z 的输入.

incorporated input from @MatthewScharley regarding git ls-files -z.

注意:如果您使用的是 Windows,请使用 Git Bash 来运行这些命令

这篇关于git update-index --assume-unchanged 在目录上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 10:56