]> git.99rst.org Git - git.git/commit
replay: add --revert mode to reverse commit changes
authorSiddharth Asthana <redacted>
Wed, 25 Mar 2026 20:23:52 +0000 (01:53 +0530)
committerJunio C Hamano <redacted>
Wed, 25 Mar 2026 21:21:20 +0000 (14:21 -0700)
commit2760ee49834953c0860fa5d7983a6af4d27cb6a9
tree9798f8a97b0a3a52c048501c9990756da1a42e88
parent1e6434ebbd63d4ec0ad2f8bccf25bd0d98d55030
replay: add --revert mode to reverse commit changes

Add a `--revert <branch>` mode to git replay that undoes the changes
introduced by the specified commits. Like --onto and --advance, --revert
is a standalone mode: it takes a branch argument and updates that branch
with the newly created revert commits.

At GitLab, we need this in Gitaly for reverting commits directly on bare
repositories without requiring a working tree checkout.

The approach is the same as sequencer.c's do_pick_commit() -- cherry-pick
and revert are just the same three-way merge with swapped arguments:

  - Cherry-pick: merge(ancestor=parent, ours=current, theirs=commit)
  - Revert: merge(ancestor=commit, ours=current, theirs=parent)

We swap the base and pickme trees passed to merge_incore_nonrecursive()
to reverse the diff direction.

Reverts are processed newest-first (matching git revert behavior) to
reduce conflicts by peeling off changes from the top. Each revert
builds on the result of the previous one via the last_commit fallback
in the main replay loop, rather than relying on the parent-mapping
used for cherry-pick.

Revert commit messages follow the usual git revert conventions: prefixed
with "Revert" (or "Reapply" when reverting a revert), and including
"This reverts commit <hash>.". The author is set to the current user
rather than preserving the original author, matching git revert behavior.

Helped-by: Christian Couder <redacted>
Helped-by: Patrick Steinhardt <redacted>
Helped-by: Elijah Newren <redacted>
Helped-by: Phillip Wood <redacted>
Helped-by: Johannes Schindelin <redacted>
Helped-by: Junio C Hamano <redacted>
Helped-by: Toon Claes <redacted>
Signed-off-by: Siddharth Asthana <redacted>
Signed-off-by: Junio C Hamano <redacted>
Documentation/git-replay.adoc
builtin/replay.c
replay.c
replay.h
t/t3650-replay-basics.sh
git clone https://git.99rst.org/PROJECT