After I run git update-index --assume-unchanged path/to/file
on a particular branch, I'm unable to switch branches using git checkout
.
It throws the following error:
error: Your local changes to the following files would be overwritten by checkout:
path/to/file
Please, commit your changes or stash them before you can switch branches.
Aborting
But both git diff
& git status
tells me there is no difference & there is nothing to commit/stash.
How do I switch out of the branch?
Is there a better alternative to git update-index --assume-unchanged
(other than .gitignore
, because I don't want it to be ignored)? (Same as question 2 @ git update-index --no-assume-unchanged doesn't work)
When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git.
The git checkout command lets you navigate between the branches created by git branch . Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch.
After some amount of use I now prefer git update-index --skip-worktree
which is a much better alternative to the git update-index --assume-unchanged
.
Check out Difference Between 'assume-unchanged' and 'skip-worktree' for further information.
I also am planning to check out the method specified in this answer to git assume unchanged vs skip worktree - ignoring a symbolic link, which seems to be more defensive approach.
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