Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/Documentation/git-rebase.adoc # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / Documentation / git-rebase.adoc` 1305 lines ยท 48089 bytes Raw Blame History 1 git-rebase(1) 2 ============= 3 4 NAME 5 ---- 6 git-rebase - Reapply commits on top of another base tip 7 8 SYNOPSIS 9 -------- 10 [verse] 11 'git rebase' [-i | --interactive] [] [--exec ] 12 [--onto | --keep-base] [ []] 13 'git rebase' [-i | --interactive] [] [--exec ] [--onto ] 14 --root [] 15 'git rebase' (--continue|--skip|--abort|--quit|--edit-todo|--show-current-patch) 16 17 DESCRIPTION 18 ----------- 19 Transplant a series of commits onto a different starting point. 20 You can also use `git rebase` to reorder or combine commits: see 21 <> below for how to do that. 22 23 For example, imagine that you have been working on the `topic` branch in this 24 history, and you want to "catch up" to the work done on the `master` branch. 25 26 ------------ 27 A---B---C topic 28 / 29 D---E---F---G master 30 ------------ 31 32 You want to transplant the commits you made on `topic` since it diverged from 33 `master` (i.e. A, B, and C), on top of the current `master`. You can do this 34 by running `git rebase master` while the `topic` branch is checked out. If you 35 want to rebase `topic` while on another branch, `git rebase master topic` is a 36 shortcut for `git checkout topic && git rebase master`. 37 38 ------------ 39 A'--B'--C' topic 40 / 41 D---E---F---G master 42 ------------ 43 44 45 If there is a merge conflict during this process, `git rebase` will stop at the 46 first problematic commit and leave conflict markers. If this happens, you can do 47 one of these things: 48 49 1. Resolve the conflict. After resolving all of the conflicts, 50 you can continue the rebasing process with 51 52 git rebase --continue 53 54 2. Stop the `git rebase` and return your branch to its original state with 55 56 git rebase --abort 57 58 3. Skip the commit that caused the merge conflict with 59 60 git rebase --skip 61 62 See linkgit:gitmergeconflicts[7] (or `git help mergeconflicts`) 63 for a full guide to handling merge conflicts. 64 65 If you don't specify an `` to rebase onto, the upstream configured in 66 `branch..remote` and `branch..merge` options will be used (see 67 linkgit:git-config[1] for details) and the `--fork-point` option is 68 assumed. If you are currently not on any branch or if the current 69 branch does not have a configured upstream, the rebase will abort. 70 71 Here is a simplified description of what `git rebase ` does: 72 73 1. Make a list of all commits on your current branch since it branched 74 off from `` that do not have an equivalent commit in 75 ``. 76 2. Check out `` with the equivalent of 77 `git checkout --detach `. 78 3. Replay the commits, one by one, in order. This is similar to running 79 `git cherry-pick ` for each commit. 80 See <> for how merges are handled. 81 4. Update your branch to point to the final commit with the equivalent 82 of `git checkout -B `. 83 84 [NOTE] 85 When starting the rebase, `ORIG_HEAD` is set to point to the commit at the tip 86 of the to-be-rebased branch. However, `ORIG_HEAD` is not guaranteed to still 87 point to that commit at the end of the rebase if other commands that change 88 `ORIG_HEAD` (like `git reset`) are used during the rebase. The previous branch 89 tip, however, is accessible using the reflog of the current branch (i.e. `@{1}`, 90 see linkgit:gitrevisions[7]). 91 92 [[TRANSPLANTING]] 93 TRANSPLANTING A TOPIC BRANCH WITH --ONTO 94 ---------------------------------------- 95 96 Here is how you would transplant a topic branch based on one 97 branch to another, to pretend that you forked the topic branch 98 from the latter branch, using `rebase --onto`. 99 100 First let's assume your 'topic' is based on branch 'next'. 101 For example, a feature developed in 'topic' depends on some 102 functionality which is found in 'next'. 103 104 ------------ 105 o---o---o---o---o master 106 \ 107 o---o---o---o---o next 108 \ 109 o---o---o topic 110 ------------ 111 112 We want to make 'topic' forked from branch 'master'; for example, 113 because the functionality on which 'topic' depends was merged into the 114 more stable 'master' branch. We want our tree to look like this: 115 116 ------------ 117 o---o---o---o---o master 118 | \ 119 | o'--o'--o' topic 120 \ 121 o---o---o---o---o next 122 ------------ 123 124 We can get this using the following command: 125 126 git rebase --onto master next topic 127 128 129 Another example of --onto option is to rebase part of a 130 branch. If we have the following situation: 131 132 ------------ 133 H---I---J topicB 134 / 135 E---F---G topicA 136 / 137 A---B---C---D master 138 ------------ 139 140 then the command 141 142 git rebase --onto master topicA topicB 143 144 would result in: 145 146 ------------ 147 H'--I'--J' topicB 148 / 149 | E---F---G topicA 150 |/ 151 A---B---C---D master 152 ------------ 153 154 This is useful when topicB does not depend on topicA. 155 156 A range of commits could also be removed with rebase. If we have 157 the following situation: 158 159 ------------ 160 E---F---G---H---I---J topicA 161 ------------ 162 163 then the command 164 165 git rebase --onto topicA~5 topicA~3 topicA 166 167 would result in the removal of commits F and G: 168 169 ------------ 170 E---H'---I'---J' topicA 171 ------------ 172 173 This is useful if F and G were flawed in some way, or should not be 174 part of topicA. Note that the argument to `--onto` and the `` 175 parameter can be any valid commit-ish. 176 177 MODE OPTIONS 178 ------------ 179 180 The options in this section cannot be used with any other option, 181 including not with each other: 182 183 --continue:: 184 Restart the rebasing process after having resolved a merge conflict. 185 186 --skip:: 187 Restart the rebasing process by skipping the current patch. 188 189 --abort:: 190 Abort the rebase operation and reset HEAD to the original 191 branch. If `` was provided when the rebase operation was 192 started, then `HEAD` will be reset to ``. Otherwise `HEAD` 193 will be reset to where it was when the rebase operation was 194 started. 195 196 --quit:: 197 Abort the rebase operation but `HEAD` is not reset back to the 198 original branch. The index and working tree are also left 199 unchanged as a result. If a temporary stash entry was created 200 using `--autostash`, it will be saved to the stash list. 201 202 --edit-todo:: 203 Edit the todo list during an interactive rebase. 204 205 --show-current-patch:: 206 Show the current patch in an interactive rebase or when rebase 207 is stopped because of conflicts. This is the equivalent of 208 `git show REBASE_HEAD`. 209 210 OPTIONS 211 ------- 212 --onto :: 213 Starting point at which to create the new commits. If the 214 `--onto` option is not specified, the starting point is 215 ``. May be any valid commit, and not just an 216 existing branch name. 217 + 218 As a special case, you may use "A\...B" as a shortcut for the 219 merge base of A and B if there is exactly one merge base. You can 220 leave out at most one of A and B, in which case it defaults to HEAD. 221 222 See <> 223 above for examples. 224 225 --keep-base:: 226 Set the starting point at which to create the new commits to the 227 merge base of `` and ``. Running 228 `git rebase --keep-base ` is equivalent to 229 running 230 `git rebase --reapply-cherry-picks --no-fork-point --onto ... `. 231 + 232 This option is useful in the case where one is developing a feature on 233 top of an upstream branch. While the feature is being worked on, the 234 upstream branch may advance and it may not be the best idea to keep 235 rebasing on top of the upstream but to keep the base commit as-is. As 236 the base commit is unchanged this option implies `--reapply-cherry-picks` 237 to avoid losing commits. 238 + 239 Although both this option and `--fork-point` find the merge base between 240 `` and ``, this option uses the merge base as the _starting 241 point_ on which new commits will be created, whereas `--fork-point` uses 242 the merge base to determine the _set of commits_ which will be rebased. 243 + 244 See also <> below. 245 246 :: 247 Upstream branch to compare against. May be any valid commit, 248 not just an existing branch name. Defaults to the configured 249 upstream for the current branch. 250 251 :: 252 Working branch; defaults to `HEAD`. 253 254 --apply:: 255 Use applying strategies to rebase (calling `git-am` 256 internally). This option may become a no-op in the future 257 once the merge backend handles everything the apply one does. 258 + 259 See also <> below. 260 261 --empty=(drop|keep|stop):: 262 How to handle commits that are not empty to start and are not 263 clean cherry-picks of any upstream commit, but which become 264 empty after rebasing (because they contain a subset of already 265 upstream changes): 266 + 267 -- 268 `drop`;; 269 The commit will be dropped. This is the default behavior. 270 `keep`;; 271 The commit will be kept. This option is implied when `--exec` is 272 specified unless `-i`/`--interactive` is also specified. 273 `stop`;; 274 `ask`;; 275 The rebase will halt when the commit is applied, allowing you to 276 choose whether to drop it, edit files more, or just commit the empty 277 changes. This option is implied when `-i`/`--interactive` is 278 specified. `ask` is a deprecated synonym of `stop`. 279 -- 280 + 281 Note that commits which start empty are kept (unless `--no-keep-empty` 282 is specified), and commits which are clean cherry-picks (as determined 283 by `git log --cherry-mark ...`) are detected and dropped as a 284 preliminary step (unless `--reapply-cherry-picks` or `--keep-base` is 285 passed). 286 + 287 See also <> below. 288 289 --no-keep-empty:: 290 --keep-empty:: 291 Do not keep commits that start empty before the rebase 292 (i.e. that do not change anything from its parent) in the 293 result. The default is to keep commits which start empty, 294 since creating such commits requires passing the `--allow-empty` 295 override flag to `git commit`, signifying that a user is very 296 intentionally creating such a commit and thus wants to keep 297 it. 298 + 299 Usage of this flag will probably be rare, since you can get rid of 300 commits that start empty by just firing up an interactive rebase and 301 removing the lines corresponding to the commits you don't want. This 302 flag exists as a convenient shortcut, such as for cases where external 303 tools generate many empty commits and you want them all removed. 304 + 305 For commits which do not start empty but become empty after rebasing, 306 see the `--empty` flag. 307 + 308 See also <> below. 309 310 --reapply-cherry-picks:: 311 --no-reapply-cherry-picks:: 312 Reapply all clean cherry-picks of any upstream commit instead 313 of preemptively dropping them. (If these commits then become 314 empty after rebasing, because they contain a subset of already 315 upstream changes, the behavior towards them is controlled by 316 the `--empty` flag.) 317 + 318 In the absence of `--keep-base` (or if `--no-reapply-cherry-picks` is 319 given), these commits will be automatically dropped. Because this 320 necessitates reading all upstream commits, this can be expensive in 321 repositories with a large number of upstream commits that need to be 322 read. When using the 'merge' backend, warnings will be issued for each 323 dropped commit (unless `--quiet` is given). Advice will also be issued 324 unless `advice.skippedCherryPicks` is set to false (see 325 linkgit:git-config[1]). 326 + 327 `--reapply-cherry-picks` allows rebase to forgo reading all upstream 328 commits, potentially improving performance. 329 + 330 See also <> below. 331 332 --allow-empty-message:: 333 No-op. Rebasing commits with an empty message used to fail 334 and this option would override that behavior, allowing commits 335 with empty messages to be rebased. Now commits with an empty 336 message do not cause rebasing to halt. 337 + 338 See also <> below. 339 340 -m:: 341 --merge:: 342 Using merging strategies to rebase (default). 343 + 344 Note that a rebase merge works by replaying each commit from the working 345 branch on top of the `` branch. Because of this, when a merge 346 conflict happens, the side reported as 'ours' is the so-far rebased 347 series, starting with ``, and 'theirs' is the working branch. 348 In other words, the sides are swapped. 349 + 350 See also <> below. 351 352 -s :: 353 --strategy=:: 354 Use the given merge strategy, instead of the default `ort`. 355 This implies `--merge`. 356 + 357 Because `git rebase` replays each commit from the working branch 358 on top of the `` branch using the given strategy, using 359 the `ours` strategy simply empties all patches from the ``, 360 which makes little sense. 361 + 362 See also <> below. 363 364 -X :: 365 --strategy-option=:: 366 Pass the through to the merge strategy. 367 This implies `--merge` and, if no strategy has been 368 specified, `-s ort`. Note the reversal of 'ours' and 369 'theirs' as noted above for the `-m` option. 370 + 371 See also <> below. 372 373 include::rerere-options.adoc[] 374 375 -S[]:: 376 --gpg-sign[=]:: 377 --no-gpg-sign:: 378 GPG-sign commits. The `keyid` argument is optional and 379 defaults to the committer identity; if specified, it must be 380 stuck to the option without a space. `--no-gpg-sign` is useful to 381 countermand both `commit.gpgSign` configuration variable, and 382 earlier `--gpg-sign`. 383 384 -q:: 385 --quiet:: 386 Be quiet. Implies `--no-stat`. 387 388 -v:: 389 --verbose:: 390 Be verbose. Implies `--stat`. 391 392 --stat:: 393 Show a diffstat of what changed upstream since the last rebase. The 394 diffstat is also controlled by the configuration option rebase.stat. 395 396 -n:: 397 --no-stat:: 398 Do not show a diffstat as part of the rebase process. 399 400 --no-verify:: 401 This option bypasses the pre-rebase hook. See also linkgit:githooks[5]. 402 403 --verify:: 404 Allows the pre-rebase hook to run, which is the default. This option can 405 be used to override `--no-verify`. See also linkgit:githooks[5]. 406 407 -C:: 408 Ensure at least `` lines of surrounding context match before 409 and after each change. When fewer lines of surrounding 410 context exist they all must match. By default no context is 411 ever ignored. Implies `--apply`. 412 + 413 See also <> below. 414 415 --no-ff:: 416 --force-rebase:: 417 -f:: 418 Individually replay all rebased commits instead of fast-forwarding 419 over the unchanged ones. This ensures that the entire history of 420 the rebased branch is composed of new commits. 421 + 422 You may find this helpful after reverting a topic branch merge, as this option 423 recreates the topic branch with fresh commits so it can be remerged 424 successfully without needing to "revert the reversion" (see the 425 link:howto/revert-a-faulty-merge.html[revert-a-faulty-merge How-To] for 426 details). 427 428 --fork-point:: 429 --no-fork-point:: 430 Use reflog to find a better common ancestor between `` 431 and `` when calculating which commits have been 432 introduced by ``. 433 + 434 When `--fork-point` is active, 'fork_point' will be used instead of 435 `` to calculate the set of commits to rebase, where 436 'fork_point' is the result of `git merge-base --fork-point 437 ` command (see linkgit:git-merge-base[1]). If 'fork_point' 438 ends up being empty, the `` will be used as a fallback. 439 + 440 If `` or `--keep-base` is given on the command line, then 441 the default is `--no-fork-point`, otherwise the default is 442 `--fork-point`. See also `rebase.forkpoint` in linkgit:git-config[1]. 443 + 444 If your branch was based on `` but `` was rewound and 445 your branch contains commits which were dropped, this option can be used 446 with `--keep-base` in order to drop those commits from your branch. 447 + 448 See also <> below. 449 450 --ignore-whitespace:: 451 Ignore whitespace differences when trying to reconcile 452 differences. Currently, each backend implements an approximation of 453 this behavior: 454 + 455 apply backend;; 456 When applying a patch, ignore changes in whitespace in context 457 lines. Unfortunately, this means that if the "old" lines being 458 replaced by the patch differ only in whitespace from the existing 459 file, you will get a merge conflict instead of a successful patch 460 application. 461 + 462 merge backend;; 463 Treat lines with only whitespace changes as unchanged when merging. 464 Unfortunately, this means that any patch hunks that were intended 465 to modify whitespace and nothing else will be dropped, even if the 466 other side had no changes that conflicted. 467 468 --whitespace=