git commit . ignoring assume-unchanged

96 views Asked by At

I have a file which I have marked assume-unchanged in my checkout. This is respected by most commands (e.g. diff, add ., commit -a), but for some reason this command seems to be ignoring the flag:

git commit .

Is this a bug? If not, is there a flag to change git's behaviour in this case?

(My git version in 2.25.1, should that be important.)

1

There are 1 answers

0
bk2204 On BEST ANSWER

The assume-unchanged flag to Git is used to improve performance on systems with slow lstat(2) calls. When you set this bit, you promise not to change the file at all. If you are changing the file, then you must unset the bit to notify Git that it's changed. This is a performance optimization only.

If you are trying to ignore changes to tracked files, the 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.

The FAQ recommends an approach for configuration files:

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.