Search code examples
gitphpstormgit-squash

How to reset rebase squash?


How do I reset git squash?

I am using PhpStorm. I squashed commits from last 14 days of work. The commit "HEAD DEV Refactor gulp file" has 50+ squashed commits inside.

How do I show / unsquash them again?

enter image description here


Solution

  • There is no "unsquashing" in Git normally. I am not familiar with your tool, so my answer applies for the Git command line. If you're on Windows, you probably have Git bash installed, and the tool may have a direct way of launching the Git commandline.

    Make a backup of your state to prevent getting into worse trouble:

    git tag unsquash-backup
    

    First check if ORIG_HEAD is set to something you like. This should be the last state you had before a rebase.

    git show ORIG_HEAD
    

    If you see that it is the state you want to go back to, just do

    git reset --hard ORIG_HEAD
    git rebase --abort
    

    If ORIG_HEAD is no longer what you want, you should use git reflog, which is the usual way of getting yourself out of trouble in Git if you've done something you shouldn't have.

    git reflog
    

    Then look for an old commit (which will look something like HEAD@{8}) in the list. That should be the state you want to go back to. Check that commit's history first to be sure by

    git log HEAD@{8}
    

    And then you can reset your branch to that state.

    git reset --hard HEAD@{8}
    

    Of course substituting HEAD@{8} everywhere with the commit you found in git reflog.

    Note: standard warning applies, if you use git reset --hard, you lose any current uncommitted changes.