Git feature –assume-unchanged

This is a cool feature. You can mark files as “yes, I know this is tracked by Git, but I don’t want my changes committed.”

For example, there’s a config file that’s checked in. You need to make local edits to test with. However, you often accidentally commit those changes (you forget). But you could tell Git to ignore changes in this file. Let’s say we have a file config.xml that we want to edit locally and leave edited.

git update-index --assume-unchanged config.xml

After this, we can commit all we want, and Git will ignore config.xml. If you need to commit a change to it, you can undo this with

git update-index --no-assume-unchanged config.xml

If you’ve forgotten which files you have set the “assume unchanged” bit on, you can do git ls-files -v to see.

This is an edge case, but useful for some work flows.

2 thoughts on “Git feature –assume-unchanged”

  1. I like this as well. You can improve the usability of this feature with these macros that I found somewhere out there. Put these in your git config

    [alias]
    assume = update-index --assume-unchanged
    unassume = update-index --no-assume-unchanged
    assumed = "!git ls-files -v | grep ^h | cut -c 3-"

    This lets you do something like git assumed to list those items which you’re currently ignoring.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>