Undo a Mistake made while squashing the commits in GIT

前端 未结 2 1013
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-04 04:16

I wanted to squash my last 2 commits into one, so did a git rebase, in following way:

git rebase -i HEAD~2

but due to a typo, wha

相关标签:
2条回答
  • 2021-02-04 04:21

    Edit: Check your reflog with

    git reflog
    

    Pick the commit previous to your first rebase and replace the x with appropriate number below:

    Just undo your last rebase and redo it:

    git reset --hard HEAD@{x}
    git rebase -i HEAD~2
    ..
    git push -f origin master
    

    Remove your pull request and issue a new one.

    0 讨论(0)
  • 2021-02-04 04:27

    Both git reset --hard HEAD{x} and git reset --hard HEAD@{x} didn't work for me.

    I wanted a script to do this anyways, so I did the following.

    BACK_2_SHA=`git reflog show --pretty=format:'%H' -n x | tail -n 1`
    git reset --hard $BACK_2_SHA
    
    0 讨论(0)
提交回复
热议问题