With git, temporary exclude a changed tracked file from commit in command line
I have a tracked database (already added) file in git. I want this file to always contain the same data in my git repository. Even when I modify it in the working copy (local sandbox) for test purposes.
With git, how to exclude this changed file on my working copy from a commit ?
6 Solutions collect form web for “With git, temporary exclude a changed tracked file from commit in command line”
The way to ignore certain files that are already committed is
git update-index --assume-unchanged file
However, this is a local setting, and it doesn’t propagate when cloning.
Its effect is canceled with
git update-index --no-assume-unchanged gui.
Additionally to using
git add I would suggest to use a shell with more capabilities, i.e. zsh. Here you can insert extended globbing like
*~*.o(.) which means all files except such ending with
o. This make it easier to add all files except one. Zsh also allows you to set a global alias:
alias -g AF="*~*.o(.)". So you can type
git add AF and it will be expanded in the right way.
If you don’t do
git commit -a,
git commit will only commit files that you have explicitly added to the index using
simply do not add it with
git add, but add any other file you want to commit
git commit instead of
git commit -a
The smarter way to do this is to not track the database at all, directly. Track an example database and then each developer can copy it and modify it, and it can be under gitignore.
- add this file to your repo
- add it to