Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to undo a successful "git cherry-pick"?

Tags:

git

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 this anywhere.

How can I remove just this cherry pick?

I'd like to know if there's a way to do this:

  • when I have other local changes
  • when I have no other local changes

Preferably with one command for both cases if possible.

like image 742
Brad Parks Avatar asked Oct 11 '22 17:10

Brad Parks


People also ask

How do I cancel git cherry-picking?

Try also with '--quit' option, which allows you to abort the current operation and further clear the sequencer state. --quit Forget about the current operation in progress. Can be used to clear the sequencer state after a failed cherry-pick or revert.

How do you change a cherry pick?

To change the commit message when cherry-picking, use “git cherry-pick” with the “-e” option. As illustrated in this example, your default editor will open and it will let you change the commit message.


1 Answers

A cherry-pick is basically a commit, so if you want to undo it, you just undo the commit.

when I have other local changes

Stash your current changes so you can reapply them after resetting the commit.

$ git stash
$ git reset --hard HEAD^
$ git stash pop  # or `git stash apply`, if you want to keep the changeset in the stash

when I have no other local changes

$ git reset --hard HEAD^
like image 223
Tim Avatar answered Oct 14 '22 07:10

Tim