git 不会忽略 2 个特定命名的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10879783/
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 doesn't ignore 2 specifically named files
提问by erikbwork
I want to automatically exclude 2 files from committing, that are part of the git repository but have some changes, that shouldn't be part of the github repo, because they have some changes that are only meaningful to my local system and not the other developers.
我想自动从提交中排除 2 个文件,它们是 git 存储库的一部分,但有一些更改,它们不应该是 github 存储库的一部分,因为它们有一些更改仅对我的本地系统有意义,而对另一个没有意义开发商。
I added them to .git/info/exclude
in the hopes git understands that he shouldn't commit changes to them:
我将它们添加到.git/info/exclude
希望 git 明白他不应该对它们进行更改:
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
a.conf
b.conf
# *~
but git status
still lists them as staged for committing:
但git status
仍将它们列为已提交:
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: build/conf/a.conf
# modified: build/conf/b.conf
#
I don't want to unstage them regularly with every commit (one time I might just forget), how can I do that?
我不想在每次提交时定期取消它们(有一次我可能会忘记),我该怎么做?
回答by eckes
What you want to is to ignore changes on tracked files. This cannot achieved (as Charles Baileysays) correctly, neither with .gitignore
nor with .git/info/exclude
.
您想要的是忽略对跟踪文件的更改。这无法正确实现(如Charles Bailey所说),无论是 with.gitignore
还是 with .git/info/exclude
。
You'll need to use git update-index
:
你需要使用git update-index
:
git update-index --assume-unchanged build/conf/a.conf
git update-index --assume-unchanged build/conf/b.conf
will achieve what you want: the files are always assumed unchanged.
将实现您想要的:始终假定文件未更改。
If you want to track changes in these files again, use --no-assume-unchanged
.
如果要再次跟踪这些文件中的更改,请使用--no-assume-unchanged
.
Finally, if you want to know which files are currently in the --assume-unchanged
mode, ask git for
最后,如果你想知道当前有哪些文件处于该--assume-unchanged
模式,请向 git 询问
git ls-files -v | grep -e "^[hsmrck]"