How to stash unmerged code in git?

poundifdef picture poundifdef · May 2, 2012 · Viewed 8.4k times · Source

I did a git pull and found that one of my files needs to be merged.

I don't really want to merge that file right now - I have another branch that I need to work on, and I will get back to this branch later to resolve the merge.

What is the best course of action for me to "undo" this pull? Or how can I hold off on this merge until I'm ready to deal with it? What do I need to do to be able to change branches, but then return to this unmerged state in my code?

Answer

Tim Jarvis picture Tim Jarvis · May 2, 2012

This is a good example of why I reckon doing a fetch instead of a pull is a good idea.

What you can do is simply reset your branch to it's previous state..

git reset --hard HEAD~1

or if you are already in the middle of the merge (resolving conflicts), just abort it..

git merge --abort

finish your changes and then...

git fetch
...have a look at what's changed 
git merge origin/branch 

An easy way to see what has changed is to do

git cherry branch origin/branch -v --abbrev=6

That will give you a list of commits that are in the origin branch but not in your branch...if you need the details of what changed in that commit then

git show commit --name-status