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 ?
Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.
Simply move the files to a folder outside of git, then do "git add .", "git commit". (This removed the files) then add the gitignore, referencing the files/folders, commit again to add the gitignore file to git, then copy/move back in the folders, and they should be ignored.
To remove a file from Git, you have to remove it from your tracked files (more accurately, remove it from your staging area) and then commit. The git rm command does that, and also removes the file from your working directory so you don't see it as an untracked file the next time around.
Use Git update-index to ignore changes To resume tracking, run the git update-index command with the --no-skip-worktree flag. Or, you can temporarily stop tracking a file and have Git ignore changes to the file by using the git update-index command with the assume-unchanged flag.
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 git add
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With