How to undo a git merge squash?

I have just done a

git merge --squash feature-branch

into my develop branch.

  • Reusing git branch names
  • Heroku Rails “Application Error”
  • Git. Checkout feature branch between merge commits
  • What does the shell script in git-stash mean and how does it work?
  • Why is it resulting in a merge conflict?
  • can't pop named stash in git
  • The problem is that the above command updated the head without creating a new commit. My intention was to create one single commit to apply to the head of develop.

    So in short, the log for the develop branch before and after the merge are exactly the same.

    Is there a way to revert back develop to what it was before the git merge?

    Thank you.


    Based on the comment from Dan D. and the accepted answer below I was able to resolve my problem. See below what I did in case you are in the same boat:

    1 – I ran git reflog and it listed all the commits and checkouts I did with my develop branch.

    2 – Instead of doing a git reset HEAD@{1} as suggested, I found the number when I did the last commit to develop that I wanted to keep. In my case it was HEAD@{188}. So I typed git reset HEAD@{188}.

    3 – I ran a git log and it had a clean log showing only the commits I had before I did the wrong merge.

    4 – I ran git add -A . to stage all the new files created during my feature development.

    5 – I ran git commit -m "install feature-x"

    6 – As a result now I have branch develop with the correct files and the log is clean – showing only one commit for all the changes I did during the development of feature-x.

    I still need to find out why my original git merge --squash feature-branch did not work as intended.

    Solution 2

    Mark Longair’s answer is a definitive solution to my problem. I have just tested it and it works. See below the process I am using now to squash all the internal commits within a feature-branch and include just one commit to the develop branch:

    git checkout develop
    git merge --squash feature-branch
    git commit -m "install of feature-branch"

    The above sequence works like a charm.

  • Git Copy a folder from master branch to another branch
  • Git barebones repo
  • Merging branches With Git
  • Git filter-branch gave me two sets of commits
  • What's happened to my directory on GitHub?
  • For the Jenkins git plugin, where is it recommended to run `git config`?
  • 2 Solutions collect form web for “How to undo a git merge squash?”

    If you run git merge --squash <other-branch> the working tree and index are updated with what the result of the merge would be, but it doesn’t create the commit. All you need to do is to run:

    git commit

    However, if you change your mind before committing and just want to abort the merge, you can simply run:

    git reset --merge

    You don’t need to use the reflog.

    If you change your mind before committing, you have these options:

    Abort the merge with modern git syntax:

    git merge --abort

    And with older syntax:

    git reset --merge

    And really old-school:

    git reset --hard

    But actually, it is worth noticing that git merge --abort is only equivalent to git reset --merge given that MERGE_HEAD is present. This can be read in the git help for merge command.

    git merge --abort is equivalent to git reset --merge when MERGE_HEAD is present.

    After a failed merge, when there is no MERGE_HEAD, the failed merge can be undone with git reset --merge but not necessarily with git merge --abort, so they are not only old and new syntax for the same thing. Personally I find git reset --merge much more useful in everyday work.

    Git Baby is a git and github fan, let's start git clone.