git update-index --assume-unchanged 在目录上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12288212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git update-index --assume-unchanged on directory
提问by Xander Dunn
git 1.7.12
混帐 1.7.12
I want to mark all files below a given directory as assume-unchanged.
我想将给定目录下的所有文件标记为假设未更改。
1) git update-index --assume-unchaged dir/
gives "Ignoring path."
1)git update-index --assume-unchaged dir/
给出“忽略路径”。
2) git update-index --assume-unchaged dir/*
quickly fails because it will encounter files which are not being tracked, hence it gives "fatal: Unable to mark file" and quits.
2)git update-index --assume-unchaged dir/*
很快失败,因为它会遇到未被跟踪的文件,因此它给出“致命:无法标记文件”并退出。
3) Try generating a list of files to mark. cd
into the desired directory and then run git ls-files | tr '\n' ' ' | 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 '\n' ' '
, 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?
3) 尝试生成要标记的文件列表。 cd
进入所需目录,然后运行git ls-files | tr '\n' ' ' | git update-index --assume-unchanged
. 这不会产生错误消息,但不会成功标记文件。命令的第一部分git ls-files | tr '\n' ' '
,正确地生成了我想要标记的所有文件的空格分隔列表。如果我将该命令的输出复制并粘贴到命令行上,则该git update-index
命令有效。什么不适用于管道?
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.
不,我添加dir
到 .gitignore是不够的。我需要将这些文件放在存储库中,但会在本地进行不需要的更改,需要忽略这些更改,以便用户可以进行拉取。
回答by twalberg
git update-index
wants the file names on its command line, not on its standard input.
git update-index
希望文件名在其命令行上,而不是在其标准输入上。
Step 1:
第1步:
cd
into the folder you want to assume is unchanged
cd
进入您要假设的文件夹未更改
Step 2:
第2步:
You can do either this:
你可以这样做:
git update-index --assume-unchanged $(git ls-files | tr '\n' ' ')
or
或者
git ls-files | tr '\n' ' ' | 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
Edit: incorporated input from @MatthewScharley regarding git ls-files -z
.
编辑:合并了@MatthewScharley 关于git ls-files -z
.
Windows Commands
Windows 命令
Note:If you're on windows, use Git Bashto run these commands
注意:如果您使用的是 Windows,请使用Git Bash来运行这些命令
回答by theycallhimart
The find
command from GNU Findutils has a -exec
option which removes most of the hassle of using xargs
, although its syntax is a little special. It does however deal perfectly with filenames with spaces.
find
来自 GNU Findutils的命令有一个-exec
选项,它消除了使用 的大部分麻烦xargs
,尽管它的语法有点特殊。然而,它确实可以完美地处理带空格的文件名。
This command will get git to assume all files in and under the listed directory are unchanged:
此命令将使 git 假定列出的目录中和下的所有文件都保持不变:
find path/to/dir -type f -exec git update-index --assume-unchanged '{}' \;
Find takes every argument after -exec
until ;
(which you have to escape lest your shell eats it) and runs it once for each file found, while replacing {}
(again, single quoted so your shell won't eat it) with the found file's name.
Find 接受-exec
直到之后的每个参数;
(你必须逃避,以免你的 shell 吃掉它)并为找到的每个文件运行一次,同时用{}
找到的文件名替换(再次,单引号,所以你的 shell 不会吃它)。
Using find
's matching criteria (maximum recursion depth, whether the match is a file or is a directory, whether the filename matches an expression) and -exec
you can do all sort of powerful things.
使用find
的匹配标准(最大递归深度,匹配是文件还是目录,文件名是否与表达式匹配),-exec
您可以做各种强大的事情。
Not sure about other implementations of the find
command. YMMV.
不确定该find
命令的其他实现。天啊。
回答by Steve Pitchers
Add the directory name to .git/info/exclude
. This works for untracked files.
将目录名称添加到.git/info/exclude
. 这适用于未跟踪的文件。
回答by Victor Perov
Yeap,
是的,
git update-index --assume-unchanged
works with files only, not with directories. I think, one of faster ways:
仅适用于文件,不适用于目录。我认为,更快的方法之一:
cd dir
ls | xargs -l git update-index --assume-unchanged