Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't checkout to other branches because ignored file has local changes?

Tags:

git

I get:

$ git checkout mybranch
error: Your local changes to the following files would be overwritten by checkout:
        .idea/workspace.xml
Please, commit your changes or stash them before you can switch branches.
Aborting

But .idea/ is already in my .gitignore. If I do git status, there is also no changes showing up.

Please advice.

UPDATE:

Thanks for the advice. I wish I could go to mybranch and check, but I couldn't, because it wouldn't allow me to switch! Provided that it is the correct behaviour to ignore .idea/ (they are project config files from IDE), what should I do now? My goal is to go to mybranch and merge it with master. You can think of mybranch as a production branch and master as dev branch. Now I want to update prod as master is stable enough.

like image 952
Boyang Avatar asked Aug 04 '14 12:08

Boyang


3 Answers

In my case, it was due to my former

git update-index --assume-unchanged <filename>

that was conflicting on that file. Undoing this situation via a

git update-index --no-assume-unchanged <filename>

And committing the resulting new status, everything fixed up.

Update: fix typo in parameter.

like image 177
Patrizio Bertoni Avatar answered Oct 18 '22 03:10

Patrizio Bertoni


Check if .idea/ is also present in the .gitignore of the branch you are checking out apart from that of the branch you are currently on.

A solution is to just stash the changes made to the .idea/workspace.xml file, checkout to your mybranch and then add the .idea/ folder to .gitignore, switch back to master branch and then apply the stashed changes, then merge both the branches.

like image 1
gravetii Avatar answered Oct 18 '22 02:10

gravetii


Both answers are correct about the cause. But git stash doesn't work because either it won't stash changes made to workspace.xml which is ignored, or workspace.xml has been changed somewhere else down the tree.

What I did is to git clone the repo to somewhere else, checkout to mybranch, edit gitignore, commit and then merge from master.

like image 1
Boyang Avatar answered Oct 18 '22 03:10

Boyang