Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git checkout throws an error on --assume-unchanged files

Tags:

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)

like image 359
Sujay Avatar asked Sep 24 '12 13:09

Sujay


People also ask

What is assume unchanged in Git?

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.

Does Git checkout update files?

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.


1 Answers

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.

like image 77
Sujay Avatar answered Oct 26 '22 15:10

Sujay