[PATCH 0/1] replay: add --revert option to reverse commit changes
- From
Siddharth Asthana <siddharthasthana31@gmail.com>
- Date
- Nov 25, 2025, 17:00 UTC
- Message-ID
- <20251125170056.34489-1-siddharthasthana31@gmail.com>
The `git replay` command currently supports cherry-picking commits for server-side history rewriting, but lacks the ability to revert them. This patch adds a `--revert` option to enable reversing commits directly on bare repositories.
At GitLab, we use replay in Gitaly for efficient server-side operations. Adding revert functionality enables us to reverse problematic commits without client-side roundtrips, reducing network overhead.
The implementation leverages the insight that cherry-pick and revert are essentially the same merge operation with swapped arguments. By swapping the base and pickme trees when calling `merge_incore_nonrecursive()`, we effectively reverse the diff direction. The existing conflict handling, ref updates, and atomic transaction support work unchanged.
The revert message generation logic is extracted into a new shared `sequencer_format_revert_header()` function in `sequencer.c`, allowing code reuse between `sequencer.c` and `builtin/replay.c`. The commit messages follow `git revert` conventions, including "Revert"/"Reapply" prefixes and the original commit SHA.
This patch includes comprehensive tests covering various scenarios: bare repositories, --advance mode, conflicts, reapply behavior, and multiple commits.
Siddharth Asthana (1): replay: add --revert option to reverse commit changes
Documentation/git-replay.adoc | 35 +++++++- builtin/replay.c | 86 ++++++++++++++---- sequencer.c | 23 +++++ sequencer.h | 8 ++ t/t3650-replay-basics.sh | 160 ++++++++++++++++++++++++++++++++++ 5 files changed, 295 insertions(+), 17 deletions(-)
-- 2.51.0