git update-index --assume-unchanged 和 git reset
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6104072/
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 and git reset
提问by Ken Hirakawa
Here is the scenario:
这是场景:
In my working directory, I have a number of files (let's call them A,B,C) that I've edited. I then ran git update-index --assume-unchanged
on those files. Now git status
returns blank. Good.
在我的工作目录中,我编辑了许多文件(我们称它们为 A、B、C)。然后我运行git update-index --assume-unchanged
了这些文件。现在git status
返回空白。好的。
Now, if I do a git reset --hard
, the contents of the files A,B, and C, revert back to the contents before I've edited them and "assume-unchanged" them.
现在,如果我执行 a git reset --hard
,文件 A、B 和 C 的内容将恢复到我编辑它们之前的内容并“假设未更改”它们。
Is there a way to stop git from actually reverting files A,B, and C, and simply ignore them?
有没有办法阻止 git 实际恢复文件 A、B 和 C,而只是忽略它们?
Thanks,
谢谢,
Ken
肯
回答by manojlds
You can do:
你可以做:
git update-index --skip-worktree A
回答by Adam Dymitruk
You need to add a .gitignore
file entry for those files if you want to ignore them. Add just the .gitignore
file, commit it and you will now ignore any changes to them.
.gitignore
如果您想忽略它们,您需要为这些文件添加一个文件条目。只添加.gitignore
文件,提交它,您现在将忽略对它们的任何更改。
However, I think you need to tell us why you are doing it, what's the contents of the files, the nature of them (are they artifacts?) - then you'll get the proper answer.
但是,我认为您需要告诉我们您为什么这样做,文件的内容是什么,它们的性质(它们是人工制品吗?) - 然后您会得到正确的答案。
Also, update-index
with the assume-unchanged
is meant to be used to increase performance if your tree on your OS's file system takes a long time to gather changes for a particular path. I would not recommend using it in your case unless you are ignoring those files due to lengthy git status
or git diff
or other command execution times.
此外,update-index
与assume-unchanged
旨在使用如果您的操作系统的文件系统上树需要很长的时间来收集特定路径的改变来提高性能。我不建议在你的情况下使用它,除非你是忽略由于冗长的文件git status
或git diff
或其他命令的执行时间。
回答by ViToni
You could use
你可以用
$ git stash
$ git reset --hard
$ git stash pop