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 filenameThe 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.
- 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.