How can I prevent Git from tracking changes to a file from this validation?


I have a database configuration file that has default values that are unimportant. However, any changes to this file would contain sensitive information that should not be tracked in the repo.

I would like future pulls of the Git repository to include the default version but disregard any changes made by any user.

The following keeps a local configuration but pushes the delete to the repo resulting in issues for future pulls.

cat "app/dir/config.file" >> .gitignore
git rm --cached app/dir/config.file

The following does the job but does not persist past the push to the repo.

git update-index --assume-unchanged app/dir/config.file

This seems like a common requirement for version control around sensitive information but I can't seem to find a solution.

As usual github has a great doc on this.

Here's the relevant snippet:

Ignoring versioned files

Some files in a repository change often but are rarely committed. Usually, these are various local configuration files that are edited, but should never be committed upstream. Git lets you ignore those files by assuming they are unchanged.

  1. In Terminal, navigate to the location of your Git repository.
  2. Run the following command in your terminal:

git update-index --assume-unchanged path/to/file.txt

Once you mark a file like this, Git completely ignores any changes on it. It will never show up when running git status or git diff, nor will it ever be committed.

To make Git track the file again, simply run:

git update-index --no-assume-unchanged path/to/file.txt.