Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Allow specifying the branch name in `gh pr revert`

Aperta
#14,281 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
64/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
git, github, go, graphql
Ambito
api, cli

Direzione di ricerca

Parti dal comando gh pr revert e segui il flusso di mutazione esistente di revertPullRequest. Verifica come l’endpoint proposto per rinominare il branch e la modifica del branch di base potrebbero inserirsi dopo la creazione, quindi aggiungi la copertura per --branch e --base; il lavoro è completato quando i revert funzionano con nomi personalizzati per branch e base, preservando il commit di revert generato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement gh-pr
Describe the feature or problem you'd like to solve

gh pr revert always creates the branch that GitHub names for you: revert-<PR number>-<head branch name>. There is no way to override it.

In a repository whose ruleset enables Restrict creations, that name falls outside the allowed patterns, so the ref cannot be created and the revert fails:

Repository rule violations found
Cannot create ref due to creations being restricted.

The same limit exists in the web UI and in the GraphQL revertPullRequest mutation (RevertPullRequestInput takes only pullRequestId, title, body, draft, clientMutationId), so today there is no supported way to revert a PR in such a repository. Users have to drop down to git revert -m 1 <merge commit> by hand, which also means getting the -m flag right depending on whether the PR was merged with a merge commit or squashed.

Proposed solution

Add flags to gh pr revert:

-b, --branch <name>   Name of the branch to create for the revert
-B, --base <name>     Base branch for the revert pull request

Both can be implemented on top of what already exists, without waiting for a server-side API change:

  1. call the revertPullRequest mutation as today
  2. if --branch was given, rename the created branch via POST /repos/{owner}/{repo}/branches/{branch}/rename
  3. if --base was given, apply the equivalent of gh pr edit --base

Doing the rename server-side keeps the revert commit that GitHub generated, so the result is identical to the current behaviour apart from the branch name.

If that sequence is considered too indirect, an alternative is to compute the revert locally (git revert in a temporary worktree, push, then gh pr create), though that requires a local clone and loses the "works from anywhere" property that gh pr revert has today.

Additional context

This is currently a hard blocker rather than an inconvenience: with Restrict creations enabled, gh pr revert cannot succeed at all, and the error message does not mention the branch name, so the cause is not obvious from the output.

I have also opened a discussion for the GitHub-side parts of this (the web UI field, the branchName GraphQL input, and the error message wording): https://github.com/orgs/community/discussions/206033

Lingua principale
Go
Stelle
46.3k
Fork
9.1k
Merge medio
1g 7h
PR unite (30g)
76

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cli/cli

Tutte le issue di cli/cli

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.