12

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?

3 Answers 3

16

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
0
2

If you are looking to blow away changes on a current HEAD, git reset --hard is your ticket. This should allow you to swap branches and return to this one and redo this merge at a later date.

If you are rebasing, git rebase --abort will cancel the operation as well.

1

git stash was complaining about unmerged changes after I did a git stash pop that resulted in merge conflicts, but I had already resolved them manually.

Doing git add . and then git stash worked great.

1
  • This adds all files that were not intended to be added to commit.
    – Ulysses
    Oct 9, 2019 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.