How to undo a successful “git cherry-pick”?

后端 未结 6 1775
无人及你
无人及你 2021-01-30 02:12

On a local repo, I\'ve just executed git cherry-pick SHA without any conflicts or problems. I then realized I didn\'t want to do what I just did. I have not pushed

6条回答
  •  故里飘歌
    2021-01-30 02:40

    Faced with this same problem, I discovered if you have committed and/or pushed to remote since your successful cherry-pick, and you want to remove it, you can find the cherry-pick's SHA by running:

    git log --graph --decorate --oneline

    Then, (after using :wq to exit the log) you can remove the cherry-pick using

    git rebase -p --onto YOUR_SHA_HERE^ YOUR_SHA_HERE

    where YOUR_SHA_HERE equals the cherry-picked commit's 40- or abbreviated 7-character SHA.

    At first, you won't be able to push your changes because your remote repo and your local repo will have different commit histories. You can force your local commits to replace what's on your remote by using

    git push --force origin YOUR_REPO_NAME

    (I adapted this solution from Seth Robertson: See "Removing an entire commit.")

提交回复
热议问题