Original Title: How to make git ignore my file regardless of branching?
I have the following post-checkout file which works as expected:
#!/usr/bin/ruby
cmd = ENV["HOME"] + "/dev/pitbull/cpp/bin/gen_version.rb --write"
`#{cmd}`
The gen_version.rb script figures out a timestamp, the last master tag, and the HEAD git hash and writes to a VERSION.hpp
file which is also in git.
I then use use git update-index --assume-unchanged VERSION.hpp
to make git ignore my change.
Now, this works great if I stay on my development branch. But when I try a get checkout master
, I'm screwed:
git checkout master
error: Your local changes to the following files would be overwritten by checkout:
cpp/inc/core/util/VERSION.hpp
Please, commit your changes or stash them before you can switch branches.
Aborting
What is the right git setup so that I can update VERSION.hpp when I check out but have git ignore any changes to this file, regardless of my branch?
EDIT I changed the topic as the final solution actually addresses a broader topic which may be more useful to more users of SO. So you can read this topic two ways: with the original title and the answer below, or with the broader problem above, again with the entire solution below.