Saturday, 25 January 2014

Git: Fixing “Your local changes to the following files would be overwritten by checkout”

Git is quite a learning curve. I get the feeling I can now call myself experienced because I'm starting to search for quite indepth solutions.

Today was how to get past the error message “Your local changes to the following files would be overwritten by checkout” when trying to switch branch.

The fix was actually straight forward in this case.
git checkout filename
 The background was more interesting.

  • git status showed no differences
  • gitk also showed no changes
  • this is because I am using git --assume-unchanged a lot more for key reasons
It's the --assume-unchanged aspect that complicates things. I'm not happy to have to do it but given the work I have to do and the rules that go with it it seems the best option. That is a discussion for another time. For now this answer helped me so I hope it helps you. 

I'll now go into a little detail why the fix wasn't as obvious as it seems by showing the symptoms you get when you use --assume-unchanged

The extra detail I got from the error message was 
Please, commit your changes or stash them before you can switch branches.
It is this wording that introduced the complexity. Git was telling me a file was different when I called checkout but not when I called status ot gitk. Confusing 

My search didn't give an answer straight away. Had to do a little hunting and of course the answer was nice and simple. 

I tried:
  • git stash:  no joy because no differences were found on the branch
  • git stash save --keep-index same as git stash. No difference to stash.
Post a Comment