The best way to do this is to remove that file from the history with git rm --cached FILE
and then add it to .gitignore
. Then, the file will not be tracked and won't be modified in the future, because it won't be in the repository.
If your question is how to keep the file tracked and ignore changes to a tracked file, the Git FAQ is clear that 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.
Note that the FAQ has a recommendation for the common case of 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.