Reputation: 44361
I am in branch wip
and want to move to branch dev
. I have some not-committed changes in the working dir.
$ git checkout dev
error: Your local changes to the following files would be overwritten by checkout:
.idea/runConfigurations/celery_beat.xml
Please, commit your changes or stash them before you can switch branches.
Aborting
Ok, I get it: that file won't merge. And I do not want to lose my changes to it. What I want is:
Alternatively, I sometimes want this:
wip
branch should stay as they are, the rest of the working dir should be populated from the dev
branch. A simple git diff
will show me what changes I have after moving to the dev
branch.The way I would solve this now is:
git status
git checkout -- .
git checkout dev
git diff
gives me now the changes as compared to dev
Does git
have a built-in mechanism to do this?
Upvotes: 0
Views: 76
Reputation: 30868
#stash the changes to ".idea/runConfigurations/celery_beat.xml"
git stash
#switch to dev without conflicts or overwriting
git checkout dev
#restore ".idea/runConfigurations/celery_beat.xml" to the version before the switch
git checkout stash@{0} -- .idea/runConfigurations/celery_beat.xml
#now ".idea/runConfigurations/celery_beat.xml" is staged, in order to remove it from the index:
git reset HEAD -- .idea/runConfigurations/celery_beat.xml
#if you'd like to drop the stash entry
git stash drop
But still I have to say, it's not a good idea to track .idea
.
Upvotes: 1