Ignoring subsequent changes to a file without removing it

suggest change

Sometimes you want to have a file held in Git but ignore subsequent changes.

Tell Git to ignore changes to a file or directory using update-index:

git update-index --assume-unchanged my-file.txt

The above command instructs Git to assume my-file.txt hasn’t been changed, and not to check or report changes. The file is still present in the repository.

This can be useful for providing defaults and allowing local environment overrides, e.g.:

# create a file with some values incat <<EOFMYSQL_USER=appMYSQL_PASSWORD=FIXME_SECRET_PASSWORDEOF > .env# commit to Gitgit add .envgit commit -m "Adding .env template"# ignore future changes to .envgit update-index --assume-unchanged .env# update your passwordvi .env# no changes!git status

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents