I have a file config.txt
that is tracked by git, it is downloaded on git clone
, but I don't want anybody changing and committing it i.e. if someone changes that file I don't want their changes to be tracked thus committed & accidentally pushed.
I still want to be able to add the potential changes of config.txt
later on, but in an explicit way(could be git add -f config.txt
or something else).
Also an extra step for doing this is not desirable so git update-index --skip-worktree
or git update-index --assume-unchanged
is not a good enough solution as it is prone to human error.
Is it possible to do so in git?
You cannot ignore changes to a tracked files in Git. The Git FAQ explains:
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 work with a configuration file, then the best thing to do is add an example or template file and then either have the user copy it into place or have a script create the appropriate file. You should then ignore the location of the actual configuration file and only check in the example or the template.