You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide gh cli Support to Revert Pull Request #6034
Describe the feature or problem you’d like to solve
To support automation and CI/CD it would be beneficial for the GitHub CLI to support reverting a pull request equivalent to what the UI is able to accomplish.
Proposed solution
gh pr revert 416967111
Additional context
In a multi-contributor, pull-request managed repository there are limits to what linting/formating/plan (e.g. terraform plan) can achieve before attempting to deploy (e.g. terraform apply). To increase velocity, and minimize effort required by maintainers, it would be beneficial to be able to revert a PR following a failed build/deploy.
Reacted by Rocktim, mugi, Nikhil Jha, Julius Busch, Maxime Richard, Jón Levy, Jithil Sajan, Paul Melero, Azeem and Maxime Véroone
Thanks for the feature request! Agreed that this would be useful, but I do not think there is an API to revert a merged PR. Until then, we cannot act on adding this to CLI.
In the meantime, you can use gh pr view to determine the merge commit for a PR and use git locally to revert that merge commit:
One team is migrating from Gerrit and want to mimic some of the capabilities that Gerrit has. Gerrit has topics which are essentially multi-repo PRs. GitHub PRs are scoped to a single repo.
What they are planning to do is link a set of PRs (to simulate the topic construct). I think this request comes from their commit process - if they approve a topic, they will merge the set of PRs - but if something fails, they want to be able to revert the merge.
I feel like gh pr revert <PR> makes more sense intuitively, as in the web UI 'revert' is shown separately akin to how 'close' is shown separately.
When you revert a PR, you're not inherently "undoing" the merge, you're rather making a new change that reverts the commit itself. gh pr merge --undo might imply to some people that it will undo the state of the pull request / reopen it and so on. It could also be understood to mean restoring the branch to it's former state, as if you had force pushed an older commit back to entirely get rid of the commit history / the fact it was ever merged.
A brief status update from our Help Wanted sync, cc @babakks
We need to define Acceptance Criteria ✏️
revertpullrequestinput takes body, draft, and title. So we should probably support --body, --draft, and --title flags.
There's no clean or apparent API driven way to do --web, so we don't want that scoped in on this work.
We don't want to prompt for --body, --draft, or --title.
The URL of the new revert PR should be returned or an error if there was an error.
We do not want any local branch PR detection to decide which PR to revert, which would make the argument optional. We don't want this because the value proposition for such a feature isn't very apparent and there are light risks to reverting a PR that you didn't intend to 🤷
After that, we should mention the interested parties and see if anyone is interested in continuing the work on the #8826
Missing argument Given I run gh pr revert with no <PR> Then it exits non-zero and prints an argument error.
Accepted PR identifier formats Given a merged PR exists When I run gh pr revert 123, gh pr revert owner/repo#123, or gh pr revert https://github.com/owner/repo/pull/123 Then a revert PR is created and only its URL is printed.
Merged PR requirement Given the target PR is not merged When I run gh pr revert <PR> Then it fails (API error), no URL printed, non-zero exit.
Basic revert (no flags) Given a merged PR When I run gh pr revert <PR> Then a revert PR is created with backend-generated title/body; only URL printed.
With title/body Given I pass --title "T" and/or --body "B" When I run the command Then those values are sent; revert PR created; only URL printed.
With draft Given I pass --draft When I run the command Then the revert PR is a draft; only URL printed.
API failure (permissions / already reverted / conflict / other) Given the API rejects the mutation When I run the command Then stderr shows the API error; stdout empty; non-zero exit.
Multiple invocations Given I run the command multiple times on the same merged PR Then behavior depends solely on API response (no local duplicate guard).
No implicit PR inference Given I am on a branch related to the original PR When I omit <PR> Then the command fails as in Scenario 1 (no auto-detection).
Activity
mislav commentedon Aug 4, 2022
Thanks for the feature request! Agreed that this would be useful, but I do not think there is an API to revert a merged PR. Until then, we cannot act on adding this to CLI.
In the meantime, you can use
gh pr viewto determine the merge commit for a PR and use git locally to revert that merge commit:azizshamim commentedon Aug 5, 2022
There's a
revertResourcePathattribute in the pullrequest Object in the GraphQL API. Unsure if that's useful for request, but worth looking at.duffenterprises commentedon Jan 11, 2023
@azizshamim @mislav Any chance there has been any progress here?
vilmibm commentedon Jan 11, 2023
This URL is for use in the browser; the best the CLI could do is link to it.
colindembovsky commentedon Jan 12, 2023
One team is migrating from Gerrit and want to mimic some of the capabilities that Gerrit has. Gerrit has
topicswhich are essentially multi-repo PRs. GitHub PRs are scoped to a single repo.What they are planning to do is link a set of PRs (to simulate the
topicconstruct). I think this request comes from their commit process - if they approve atopic, they will merge the set of PRs - but if something fails, they want to be able to revert the merge.mislav commentedon Jan 27, 2023
Update: the platform team just shipped a new API to revert a PR with:
You can already use this as so:
How should we expose this as a command in gh?
gh pr revert <PR>gh pr merge --undo <PR>(sort of likegh pr ready --undo)5HT2 commentedon Jan 30, 2023
I feel like
gh pr revert <PR>makes more sense intuitively, as in the web UI 'revert' is shown separately akin to how 'close' is shown separately.When you revert a PR, you're not inherently "undoing" the merge, you're rather making a new change that reverts the commit itself.
gh pr merge --undomight imply to some people that it will undo the state of the pull request / reopen it and so on. It could also be understood to mean restoring the branch to it's former state, as if you had force pushed an older commit back to entirely get rid of the commit history / the fact it was ever merged.2 remaining items
mislav commentedon Jan 30, 2023
Work prioritization looks like this: if something is tagged
help wanted, that means that there should be enough information in the thread for an outside contributor to pick up the feature and produce a pull request. https://github.com/cli/cli/blob/trunk/.github/CONTRIBUTING.mdEventually, our team might also pick up this work, but before we manage to get to it, anyone is welcome to!
dtbell91 commentedon May 7, 2024
What's needed to help the PR progress to being reviewed and (hopefully) merged?
I'm pretty interested in using this functionality after trying out the GraphQL approach with some success.
connor15mcc commentedon Sep 10, 2024
Wanted to check in on the above as well. Happy to jump in if needed to help merge the open PR!
BagToad commentedon Apr 2, 2025
@connor15mcc there's nothing currently blocking it AFAIK - it's in our review backlog. Sorry!
connor15mcc commentedon Apr 14, 2025
Ack. LMK if I can provide an extra set of hands!
eknuth commentedon Jul 18, 2025
AI thinks you can already do that. Looks like reality needs to catch up! :)
BagToad commentedon Aug 18, 2025
Status update
A brief status update from our Help Wanted sync, cc @babakks
We need to define Acceptance Criteria ✏️
revertpullrequestinputtakesbody,draft, andtitle. So we should probably support--body,--draft, and--titleflags.--web, so we don't want that scoped in on this work.--body,--draft, or--title.After that, we should mention the interested parties and see if anyone is interested in continuing the work on the #8826
BagToad commentedon Sep 24, 2025
Acceptance Criteria
Missing argument
Given I run
gh pr revertwith no<PR>Then it exits non-zero and prints an argument error.
Accepted PR identifier formats
Given a merged PR exists
When I run
gh pr revert 123,gh pr revert owner/repo#123, orgh pr revert https://github.com/owner/repo/pull/123Then a revert PR is created and only its URL is printed.
Merged PR requirement
Given the target PR is not merged
When I run
gh pr revert <PR>Then it fails (API error), no URL printed, non-zero exit.
Basic revert (no flags)
Given a merged PR
When I run
gh pr revert <PR>Then a revert PR is created with backend-generated title/body; only URL printed.
With title/body
Given I pass
--title "T"and/or--body "B"When I run the command
Then those values are sent; revert PR created; only URL printed.
With draft
Given I pass
--draftWhen I run the command
Then the revert PR is a draft; only URL printed.
API failure (permissions / already reverted / conflict / other)
Given the API rejects the mutation
When I run the command
Then stderr shows the API error; stdout empty; non-zero exit.
Multiple invocations
Given I run the command multiple times on the same merged PR
Then behavior depends solely on API response (no local duplicate guard).
No implicit PR inference
Given I am on a branch related to the original PR
When I omit
<PR>Then the command fails as in Scenario 1 (no auto-detection).