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.
what does revert pull request do?
When you revert a pull request:
- GitHub generates a new commit: The commit contains changes to reverse the original pull request's modifications.
- It doesn’t delete history: The original pull request and its commits remain in the repository's history for traceability.
- It requires manual resolution for conflicts: If new commits after the merged pull request cause conflicts, GitHub will flag them for resolution.
How to revert the pull request in GitHub
Using the GitHub web interface
Locate the pull request:
- Navigate to the repository.
- Go to the Pull Requests tab and select the merged pull request you want to revert.
Click revert:
- On the pull request's page, locate the Revert button (it appears if the pull request was merged).
- GitHub generates a new pull request with the revert changes.
Create a revert pull request:
- Review the changes in the newly created revert pull request.
- Add a description, assign reviewers, and submit for review.
Merge the revert pull request:
- Once approved, merge the revert pull request to undo the original changes.
Revert pull request GitHub command line
To revert a pull request using Git, follow these steps:
Identify the merge commit:
Terminalgit log --mergesLook for the commit message associated with the pull request.
Revert the merge commit:
Terminalgit revert -m 1 <merge_commit_hash>-m 1
specifies the parent branch to keep (usuallymain
).- Replace <merge-commit-hash> with the actual hash of the merge commit
Push the changes:
Terminalgit push origin mainThis 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.
Integrating Graphite PR inbox for revert workflows
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.