Categories
Uncategorized

temporarily ignoring files in git

Quite often, you want to change a file temporarily whilst you work on something, but you know you don’t want to commit it. Right now I want to change my project’s logging from INFO to DEBUG, but I don’t want to commit that.

There’s a command git update-index which has a flag --assume-unchanged. And it just makes those files ignored for a while.

$ git status
# On branch master
# Changed but not updated:
#   (use "git add ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
#	modified:   src/main/webapp/WEB-INF/log4j.xml
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git update-index --assume-unchanged src/main/webapp/WEB-INF/log4j.xml
$ git status
# On branch master
nothing to commit (working directory clean)

Easy! Now, edit away.

… time passes …

And now to get everything back to normal.

$ git update-index --verbose --really-refresh
src/main/webapp/WEB-INF/log4j.xml: needs update
$ git status
# On branch master
# Changed but not updated:
#   (use "git add ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
#	modified:   src/main/webapp/WEB-INF/log4j.xml
#
no changes added to commit (use "git add" and/or "git commit -a")

I have to be honest, this is slightly hacky. It would be nice to be able to tell git “ignore this change,” in the way you can say “add this change”. But it works OK for now.

2 replies on “temporarily ignoring files in git”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s