Git Reference ยท Merging and Rebasing
git replay command
Reference for the experimental git replay: rebase, cherry-pick or revert commits without touching the working tree, with --onto, --advance, --revert and --ref-action.
git replay re-applies a range of commits on top of a different commit, entirely in memory. It never reads or writes the working tree or the index, so it works in a bare repository, on a server, and in the middle of other work without disturbing it. The result is new commit objects plus an update to the refs you name.
The command is marked experimental in its own usage text, and its options have changed between releases. Treat it as a building block for tools (hosting services use this idea to rebase or cherry-pick on the server), not as a drop-in replacement for git rebase. It stops with a non-zero exit code when a commit would conflict, because there is no working tree in which you could resolve the conflict.
git replay --onto <newbase> <revision-range> git replay --advance <branch> <revision-range> git replay --revert <branch> <revision-range>
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
git replay ([--contained] --onto=<newbase> | --advance=<branch> | --revert=<branch>) [--ref=<ref>] [--ref-action=<mode>] [--linearize] <revision-range>
| Name | Description |
|---|---|
--onto <revision> |
Replay the commits of the range on top of <revision> (rebase). The range's tip ref is moved to the new tip. |
--advance <branch> |
Replay the commits on top of <branch> and move that branch forward (cherry-pick). |
--revert <branch> |
Replay the commits as reverts on top of <branch> and move it forward. |
--contained |
With --onto, also update every other branch that points at commits inside the range, keeping stacked branches stacked. |
--ref <ref> |
Update this ref with the result instead of the one derived from the range. |
--ref-action <mode> |
update (default in recent versions) changes the refs; print only writes update <ref> <new-id> <old-id> lines to standard output. |
--[no-]linearize |
Drop merge commits and replay only the non-merge commits. |
<revision-range> |
The commits to replay, for example main..topic. |
Returns: exit status 0 on success, 1 when a commit conflicts (nothing is changed), and another non-zero status for usage errors.
Usage notes
- No worktree, no index. The command works in bare repositories and never touches your checked-out files, so
git statusis unaffected afterwards. - A checked-out branch is moved under your feet. If the branch being updated is checked out in a normal repository, its working tree is not refreshed. Replay branches that are not checked out, or run the command where nobody has them checked out.
- Conflicts stop the run. There is no
--continue. Resolve by doing the rebase withgit rebaseinstead. --ref-action=printlets scripts apply the updates themselves, for example by piping the lines togit update-ref --stdinafter checking them.- Old commits stay in the object store and in the reflog, so a replay can be undone like any rewrite.
- Older Git versions printed
updatelines by default and left the refs alone; checkgit replay -hon your version before relying on the default. - Replaying merges is not supported in the basic mode; use
--linearizeto flatten them away.
Related
git rebase,git cherry-pick,git revert,git update-ref- Lessons: Rebase, Cherry-pick