Read Anthropic’s case study about Graphite Reviewer

How to revert a pull request in GitHub

Sara Verdi
Sara Verdi
Graphite software engineer

Reverting a pull request in GitHub is an operation for undoing unintended changes merged into the main branch. It creates a new commit that reverses the changes introduced by the original pull request, leaving the repository in a state similar to before the pull request was merged. This guide explores various scenarios and tools, including Graphite's PR inbox, for managing this process efficiently.

When you revert a pull request:

  1. GitHub generates a new commit: The commit contains changes to reverse the original pull request's modifications.
  2. It doesn’t delete history: The original pull request and its commits remain in the repository's history for traceability.
  3. It requires manual resolution for conflicts: If new commits after the merged pull request cause conflicts, GitHub will flag them for resolution.
  1. Locate the pull request:

    • Navigate to the repository.
    • Go to the Pull Requests tab and select the merged pull request you want to revert.
  2. Click revert:

    • On the pull request's page, locate the Revert button (it appears if the pull request was merged).

    screenshot of revert button

    • GitHub generates a new pull request with the revert changes.
  3. Create a revert pull request:

    • Review the changes in the newly created revert pull request.
    • Add a description, assign reviewers, and submit for review.
  4. Merge the revert pull request:

    • Once approved, merge the revert pull request to undo the original changes.

To revert a pull request using Git, follow these steps:

  1. Identify the merge commit:

    Terminal
    git log --merges

    Look for the commit message associated with the pull request.

  2. Revert the merge commit:

    Terminal
    git revert -m 1 <merge_commit_hash>
    • -m 1 specifies the parent branch to keep (usually main).
    • Replace <merge-commit-hash> with the actual hash of the merge commit
  3. Push the changes:

    Terminal
    git push origin main

    This publishes the revert commit to the repository.

Reverting acts as a rollback mechanism, creating a clean commit to undo changes. This ensures:

  • Traceability: All actions are logged.
  • Minimal disruption: New development proceeds with reduced risk of unexpected conflicts.

Graphite's PR inbox can optimize how you handle reverted PRs. Graphite’s functionality mirrors an email client for PRs, ensuring efficient task prioritization. With Graphite, you can benefit from:

  • Organized sections: Easily locate revert pull requests under sections like "Needs your review" or "Recently merged."
  • Custom filters: Create filters to group revert-related tasks, simplifying management.
  • Teammate collaboration: Share inbox configurations for consistent workflows across teams.

By following these strategies and leveraging tools like Graphite's PR inbox, you can manage and revert pull requests with precision and minimize disruption to your codebase.

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2