git 提交。忽略假设不变

git commit . ignoring assume-unchanged

我有一个文件,我在结帐时将其标记为假设未更改。大多数命令(例如 diffadd .commit -a)都遵守这一点,但出于某种原因,该命令似乎忽略了标志:

git commit .

这是一个错误吗?如果不是,在这种情况下是否有一个标志来改变 git 的行为?

(我的 git 版本是 2.25.1,应该很重要吧。)

Git 的 assume-unchanged 标志用于提高 lstat(2) 调用速度较慢的系统的性能。当您设置这个位时,您承诺根本不会更改该文件。如果您要更改文件,则必须取消设置该位以通知 Git 它已更改。这只是性能优化。

如果您试图忽略对跟踪文件的更改,Git FAQ is very clear that's not possible:

Git doesn’t provide a way to do this. The reason is that if Git needs to overwrite this file, such as during a checkout, it doesn’t know whether the changes to the file are precious and should be kept, or whether they are irrelevant and can safely be destroyed. Therefore, it has to take the safe route and always preserve them.

It’s tempting to try to use certain features of git update-index, namely the assume-unchanged and skip-worktree bits, but these don’t work properly for this purpose and shouldn’t be used this way.

常见问题解答推荐了配置文件的方法:

If your goal is to modify a configuration file, it can often be helpful to have a file checked into the repository which is a template or set of defaults which can then be copied alongside and modified as appropriate. This second, modified file is usually ignored to prevent accidentally committing it.