| 1 | git-replay(1) |
| 2 | ============= |
| 3 | |
| 4 | NAME |
| 5 | ---- |
| 6 | git-replay - EXPERIMENTAL: Replay commits on a new base, works with bare repos too |
| 7 | |
| 8 | |
| 9 | SYNOPSIS |
| 10 | -------- |
| 11 | [verse] |
| 12 | (EXPERIMENTAL!) 'git replay' ([--contained] --onto=<newbase> | --advance=<branch> | --revert=<branch>) |
| 13 | [--ref=<ref>] [--ref-action=<mode>] <revision-range> |
| 14 | |
| 15 | DESCRIPTION |
| 16 | ----------- |
| 17 | |
| 18 | Takes a range of commits and replays them onto a new location. Leaves |
| 19 | the working tree and the index untouched. By default, updates the |
| 20 | relevant references using an atomic transaction (all refs update or |
| 21 | none). Use `--ref-action=print` to avoid automatic ref updates and |
| 22 | instead get update commands that can be piped to `git update-ref --stdin` |
| 23 | (see the <<output,OUTPUT>> section below). |
| 24 | |
| 25 | THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE. |
| 26 | |
| 27 | OPTIONS |
| 28 | ------- |
| 29 | |
| 30 | --onto=<newbase>:: |
| 31 | Starting point at which to create the new commits. May be any |
| 32 | valid commit, and not just an existing branch name. |
| 33 | + |
| 34 | When `--onto` is specified, the branch(es) in the revision range will be |
| 35 | updated to point at the new commits, similar to the way `git rebase --update-refs` |
| 36 | updates multiple branches in the affected range. |
| 37 | |
| 38 | --advance=<branch>:: |
| 39 | Starting point at which to create the new commits; must be a |
| 40 | branch name. |
| 41 | + |
| 42 | The history is replayed on top of the <branch> and <branch> is updated to |
| 43 | point at the tip of the resulting history. This is different from `--onto`, |
| 44 | which uses the target only as a starting point without updating it. |
| 45 | |
| 46 | --revert=<branch>:: |
| 47 | Starting point at which to create the reverted commits; must be a |
| 48 | branch name. |
| 49 | + |
| 50 | When `--revert` is specified, the commits in the revision range are reverted |
| 51 | (their changes are undone) and the reverted commits are created on top of |
| 52 | <branch>. The <branch> is then updated to point at the new commits. This is |
| 53 | the same as running `git revert <revision-range>` but does not update the |
| 54 | working tree. |
| 55 | + |
| 56 | The commit messages follow `git revert` conventions: they are prefixed with |
| 57 | "Revert" and include "This reverts commit <hash>." When reverting a commit |
| 58 | whose message starts with "Revert", the new message uses "Reapply" instead. |
| 59 | Unlike cherry-pick which preserves the original author, revert commits use |
| 60 | the current user as the author, matching the behavior of `git revert`. |
| 61 | + |
| 62 | This option is mutually exclusive with `--onto` and `--advance`. It is also |
| 63 | incompatible with `--contained` (which is a modifier for `--onto` only). |
| 64 | |
| 65 | --contained:: |
| 66 | Update all branches that point at commits in |
| 67 | <revision-range>. Requires `--onto`. |
| 68 | |
| 69 | --ref=<ref>:: |
| 70 | Override which reference is updated with the result of the replay. |
| 71 | The ref must be fully qualified. |
| 72 | When used with `--onto`, the `<revision-range>` should have a |
| 73 | single tip and only the specified reference is updated instead of |
| 74 | inferring refs from the revision range. |
| 75 | When used with `--advance` or `--revert`, the specified reference is |
| 76 | updated instead of the branch given to those options. |
| 77 | This option is incompatible with `--contained`. |
| 78 | |
| 79 | --ref-action[=<mode>]:: |
| 80 | Control how references are updated. The mode can be: |
| 81 | + |
| 82 | -- |
| 83 | * `update` (default): Update refs directly using an atomic transaction. |
| 84 | All refs are updated or none are (all-or-nothing behavior). |
| 85 | * `print`: Output update-ref commands for pipeline use. This is the |
| 86 | traditional behavior where output can be piped to `git update-ref --stdin`. |
| 87 | -- |
| 88 | + |
| 89 | The default mode can be configured via the `replay.refAction` configuration variable. |
| 90 | |
| 91 | <revision-range>:: |
| 92 | Range of commits to replay; see "Specifying Ranges" in |
| 93 | linkgit:git-rev-parse[1]. In `--advance=<branch>` or |
| 94 | `--revert=<branch>` mode, the range should have a single tip, |
| 95 | so that it's clear to which tip the advanced or reverted |
| 96 | <branch> should point. Any commits in the range whose changes |
| 97 | are already present in the branch the commits are being |
| 98 | replayed onto will be dropped. |
| 99 | |
| 100 | :git-replay: 1 |
| 101 | include::rev-list-options.adoc[] |
| 102 | |
| 103 | [[output]] |
| 104 | OUTPUT |
| 105 | ------ |
| 106 | |
| 107 | By default, or with `--ref-action=update`, this command produces no output on |
| 108 | success, as refs are updated directly using an atomic transaction. |
| 109 | |
| 110 | When using `--ref-action=print`, the output is usable as input to |
| 111 | `git update-ref --stdin`. It is of the form: |
| 112 | |
| 113 | update refs/heads/branch1 ${NEW_branch1_HASH} ${OLD_branch1_HASH} |
| 114 | update refs/heads/branch2 ${NEW_branch2_HASH} ${OLD_branch2_HASH} |
| 115 | update refs/heads/branch3 ${NEW_branch3_HASH} ${OLD_branch3_HASH} |
| 116 | |
| 117 | where the number of refs updated depends on the arguments passed and |
| 118 | the shape of the history being replayed. When using `--advance` or |
| 119 | `--revert`, the number of refs updated is always one, but for `--onto`, |
| 120 | it can be one or more (rebasing multiple branches simultaneously is |
| 121 | supported). |
| 122 | |
| 123 | There is no stderr output on conflicts; see the <<exit-status,EXIT |
| 124 | STATUS>> section below. |
| 125 | |
| 126 | [[exit-status]] |
| 127 | EXIT STATUS |
| 128 | ----------- |
| 129 | |
| 130 | For a successful, non-conflicted replay, the exit status is 0. When |
| 131 | the replay has conflicts, the exit status is 1. If the replay is not |
| 132 | able to complete (or start) due to some kind of error, the exit status |
| 133 | is something other than 0 or 1. |
| 134 | |
| 135 | EXAMPLES |
| 136 | -------- |
| 137 | |
| 138 | To simply rebase `mybranch` onto `target`: |
| 139 | |
| 140 | ------------ |
| 141 | $ git replay --onto=target origin/main..mybranch |
| 142 | ------------ |
| 143 | |
| 144 | The refs are updated atomically and no output is produced on success. |
| 145 | |
| 146 | To see what would be updated without actually updating: |
| 147 | |
| 148 | ------------ |
| 149 | $ git replay --ref-action=print --onto=target origin/main..mybranch |
| 150 | update refs/heads/mybranch ${NEW_mybranch_HASH} ${OLD_mybranch_HASH} |
| 151 | ------------ |
| 152 | |
| 153 | To cherry-pick the commits from mybranch onto target: |
| 154 | |
| 155 | ------------ |
| 156 | $ git replay --advance=target origin/main..mybranch |
| 157 | ------------ |
| 158 | |
| 159 | Note that the first two examples replay the exact same commits and on |
| 160 | top of the exact same new base, they only differ in that the first |
| 161 | updates mybranch to point at the new commits and the second updates |
| 162 | target to point at them. |
| 163 | |
| 164 | What if you have a stack of branches, one depending upon another, and |
| 165 | you'd really like to rebase the whole set? |
| 166 | |
| 167 | ------------ |
| 168 | $ git replay --contained --onto=origin/main origin/main..tipbranch |
| 169 | ------------ |
| 170 | |
| 171 | All three branches (`branch1`, `branch2`, and `tipbranch`) are updated |
| 172 | atomically. |
| 173 | |
| 174 | When calling `git replay`, one does not need to specify a range of |
| 175 | commits to replay using the syntax `A..B`; any range expression will |
| 176 | do: |
| 177 | |
| 178 | ------------ |
| 179 | $ git replay --onto=origin/main ^base branch1 branch2 branch3 |
| 180 | ------------ |
| 181 | |
| 182 | This will simultaneously rebase `branch1`, `branch2`, and `branch3`, |
| 183 | all commits they have since `base`, playing them on top of |
| 184 | `origin/main`. These three branches may have commits on top of `base` |
| 185 | that they have in common, but that does not need to be the case. |
| 186 | |
| 187 | To revert commits on a branch: |
| 188 | |
| 189 | ------------ |
| 190 | $ git replay --revert=main topic~2..topic |
| 191 | ------------ |
| 192 | |
| 193 | This reverts the last two commits from `topic`, creating revert commits on |
| 194 | top of `main`, and updates `main` to point at the result. This is useful when |
| 195 | commits from `topic` were previously merged or cherry-picked into `main` and |
| 196 | need to be undone. |
| 197 | |
| 198 | NOTE: For reverting an entire merge request as a single commit (rather than |
| 199 | commit-by-commit), consider using `git merge-tree --merge-base $TIP HEAD $BASE` |
| 200 | which can avoid unnecessary merge conflicts. |
| 201 | |
| 202 | To replay onto a specific commit while updating a different reference: |
| 203 | |
| 204 | ------------ |
| 205 | $ git replay --onto=112233 --ref=refs/heads/mybranch aabbcc..ddeeff |
| 206 | ------------ |
| 207 | |
| 208 | This replays the range `aabbcc..ddeeff` onto commit `112233` and updates |
| 209 | `refs/heads/mybranch` to point at the result. This can be useful when you want |
| 210 | to use bare commit IDs instead of branch names. |
| 211 | |
| 212 | GIT |
| 213 | --- |
| 214 | Part of the linkgit:git[1] suite |