Git – How to Tell Git Never to Update a File

gitgitignore

I have a few files in git (namely configure files), that I need to be in the git repo, but I don't want them to ever update (for some reason, running them, and make, changes the configure file).

So is there any way I can tell git to ignore any CHANGES to the file, but to keep the original file still in the repo? Currently the only way I've found out to do something like this is to add the file to the .gitignore file, and the git add the file to the project directly (using -f to override). Is there any better way?

Best Answer

You could use git update-index --assume-unchanged on the file.

--assume-unchanged option can be used as a coarse file-level mechanism to ignore uncommitted changes in tracked files (akin to what .gitignore does for untracked files). You should remember that an explicit git add operation will still cause the file to be refreshed from the working tree. Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.

Related Question