appaka

appaka

just an R + D lab

05 May 2020

How to ignore modified versioned files in Git

Who has not ever happened to commit some file that he shouldn’t? Or even worst… to push it! Or even worst! merging into master and deploy it!

Sometimes we modify some files locally because we need to do something different locally, but that change should not be committed at all. But Git always tries to put it into the stage, and it is really easy to do it by mistake, especially when there is some kind of pressure out there.

I am talking about local configuration files or just some kind of local experiments. The reason really doesn’t matter.

But, do you know? Git lets you ignore those files by assuming they are unchanged:

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

From now on Git will ignore any change on it and it will never show up for staging.

You can tell Git to track the file again with:

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

This could save your life!

Ouch!