Git 不会忽略2个特定命名的文件

我想从提交中自动排除两个文件,这两个文件是 git 存储库的一部分,但是有一些变化,这些变化不应该是 github 回购的一部分,因为它们有一些变化,这些变化只对我的本地系统有意义,而对其他开发人员没有意义。

我把它们添加到 .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
# *~

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
#

我不想每次提交都定期卸载它们(有一次我可能会忘记) ,我该怎么做呢?

22643 次浏览

What you want to is to ignore changes on tracked files. This cannot achieved (as Charles Bailey says) correctly, neither with .gitignore nor with .git/info/exclude.

You'll need to use 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.

Finally, if you want to know which files are currently in the --assume-unchanged mode, ask git for

git ls-files -v | grep -e "^[hsmrck]"