Skip to content

Cursor Cloud Agents are now in Graphite. Create, review, and ship without leaving your PR.

Read more

How to revert merged pull requests via command line tools

Sara Verdi
Sara Verdi
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Reverting a merged pull request is a crucial skill for developers looking to undo changes that have been integrated into the main branch but later identified as problematic. This guide covers the steps to revert pull requests using standard Git command line workflows for both Git and Bitbucket.

Before reverting a merge, you need to identify the commit SHA (a unique identifier for that commit) of the merge commit. You can find this using the git log command. Here's how you view the commit history:

Terminal
git log --oneline --graph

This will display a simplified commit history. Look for a commit labeled as "Merge pull request #xx from some-branch."

To revert the merge commit, use the git revert command followed by the commit SHA. Here’s an example:

Terminal
git revert -m 1 <commit-sha>

The -m 1 option tells Git to keep the parent side of the mainline, which is necessary for reverting a merge commit.

If the revert process introduces conflicts, Git will prompt you to resolve them manually. After resolving any conflicts, commit the changes:

Terminal
git commit -am "Revert merge of PR #xx"

Once the revert is committed locally, push the changes to the remote repository:

Terminal
git push origin main

This command updates the remote main branch with the reverted changes.

Bitbucket allows you to revert a merge through its UI, but you can also do this via command line using the same git revert command, as Bitbucket hosts Git repositories.

Identify the merge commit using the git log command, similar to the process in Git.

Run the git revert command with the -m 1 option to revert the specific merge commit:

Terminal
git revert -m 1 <commit-sha>

As with Git, you may need to resolve conflicts. Do this manually, then commit the changes:

Terminal
git commit -am "Revert PR merge in Bitbucket"

Push the revert to the remote Bitbucket repository:

Terminal
git push origin main

Reverting merged pull requests is an essential operation when dealing with errors in codebases. Using native Git command line tools provides a direct and controlled method to roll back changes, ensuring developers can manage and recover from problematic merges efficiently across platforms like GitHub and Bitbucket.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Built for the world’s fastest engineering teams, now available for everyone.