Web Analytics Made
Easy - StatCounter

Freezing a file in git.

I wanted to freeze a file in git, so that when someone commits, this file is not updated. The file is a user log file, so while we’re testing, it gets bigger. New users need a blank version of the file to get started, though.

I knew there were various hacky solutions involving the timing of putting the file in .gitignore, but I didn’t want to do that.

So I asked on Twitter, and Twitter came through. This StackOverflow answer has worked, where you indicate that the git index should assume the file is unchanged. So for file user-log.db,

git update-index --assume-unchanged user-log.db

with the blank user-log.db. update-index docs.

To see which files are set with the --assume-unchanged bit, here are the docs for that flag. You can run

git ls-files -v

Files where the flag is --assume-changed have H, --assume-unchanged is h. I didn’t find documentation for this, I just observed.

Then, git commit -am "blah" whatever with abandon and push, user-log.db will stay as it was when you ran the update index call.

As additional insurance, you could approach this problem with pre-commit hooks. However, that is beyond me and this project at this time, so I will leave this for later.

© Amy Tabb 2018-2021. All rights reserved. The contents of this site reflect my personal perspectives and not those of any other entity.