Book Your Free Call

How To Abort A Cherry-Pick In Git?

Tim Mouskhelichvili
Tim Mouskhelichvili
2 minutes to read

When using the git cherry-pick command, a developer may need to abort its operation. Luckily, this is very easy to do in Git.

The simplest way to abort a cherry-pick in Git is to use the --abort option:

bashgit cherry-pick --abort

This article will explain different ways of aborting a cherry-pick operation and their difference.

Let's get to it 😎.

git abort cherry pick

Why would you need to abort a cherry-pick?

Cherry-picking means choosing a commit from a branch and applying it to another one.

When you run the cherry-pick command, it will do a merge on your code.

That merge can create conflicts.

To fix those merge conflicts, you can either:

  • Fix them manually and run the git cherry-pick --continue command.
  • Abort the cherry-pick.

How to abort a cherry-pick?

There are multiple ways to abort a cherry-pick.

1. Use the abort option.

The abort option completely undoes the cherry-picking operation.

To abort a cherry-pick and completely undo the operation, use:

bashgit cherry-pick --abort

2. Use the quit option.

The quit option cleans up the cherry-pick operation and doesn't touch anything else.

To abort a cherry-pick and keep the merged changes, use:

bashgit cherry-pick --quit

3. Use the git reset command.

Another way of clearing up a conflicted cherry-pick is to use the git reset merge command.

Cherry-Pick Abort VS Quit

The biggest difference between those two options is:

  • The abort option cancels the operation and UNDOES any commits it has merged.
  • The quit option cleans up the operation and KEEPS the already merged commits.

How to undo a cherry-pick?

Since a cherry-pick is very similar to a commit, you can uncommit it the same way you would a commit.

To undo a cherry-pick, use the git reset command:

bashgit reset --hard HEAD^

Note: Learn more about HEAD here.

Final thoughts

As you can see, aborting a cherry-pick in Git is very easy.

Just use the git cherry-pick command with the --abort option.

Although the git cherry-pick command is not the most well-known command, it is best to know how to use it in different scenarios for a complete picture.

git abort cherry-pick

Here are some other Git tutorials for you to enjoy:

Comments (1)
Jack October 27, 2022 14:43PM
Very helpful. Thanks Tim.