Search code examples
gitgit-mergegit-pullgit-stash

aborting a git merge and going back to uncommitted work


this is my situation:

i forgot to pull and I started working on my project. what I worked on this morning is totally different from my last commit on that repository.

I'm doing a commit and I'm prompted to pull, this is when i realized i will have an avalanche of unresolvable conflicts.

i pull and my project is all messed up now. is there a way to going back to the work i did before performing the pull?

not reverting to my last commit because I would lose all the work i did today, but just stash all the mess and go back to 5 minutes ago?


Solution

  • First, abort the unfinished merge:

    git merge --abort
    

    Then, undo your last commit (the one that leads to the conflicts):

    git reset HEAD^
    

    This leaves the changes that you did in the commit in the worktree, so you can just go on editing.