Skip to content
Source
Sign inSign up

Revert a merge

Issues and pull requests / Pull requests

Revert a merge that broke something

A merged pull request broke the base branch. You want its changes out of the base branch, through a normal pull request.

2 min read

You need write access.

1. Open the revert pull request

On the web:

  1. Open the merged pull request.
  2. In the box This pull request is merged, click Revert.
  3. In the dialog, click Revert.

In a terminal:

src pr revert 7

The forge makes a new branch from the base branch, with a commit that undoes the pull request. Then it opens a pull request from that branch.

For a pull request that merged by rebase, that one commit undoes every commit that the rebase put on the base branch. A git server that cannot do this yet refuses the revert, and the reason gives the git revert command that does it.

  • src pr revert prints the URL of the new pull request.
  • --draft opens it as a draft.
  • --title and --body set its text.

2. Merge the revert

Merge the new pull request as any other. See Merge a pull request when its checks pass.

Done

The changes of the broken pull request left the base branch. One more pull request undid them.

Later: REST and MCP

An agent or a script does the same work over REST or MCP, with the same rules. The REST paths are under /api/v1/repos/{owner}/{repo}.

You want toRESTMCP tool
Revert a merged pull requestPOST /pulls/{n}/revert, with { "title", "body", "draft" }revert_pull