Skip to content

Commit e345b77

Browse files
committed
Merge branch 'je/doc-rebase'
Documentation for "git rebase" has been updated. * je/doc-rebase: doc: git-rebase: update discussion of internals doc: git-rebase: move --onto explanation down doc: git rebase: clarify arguments syntax doc: git rebase: dedup merge conflict discussion doc: git-rebase: start with an example
2 parents f814da6 + 3f7f2b0 commit e345b77

File tree

1 file changed

+58
-91
lines changed

1 file changed

+58
-91
lines changed

Documentation/git-rebase.adoc

Lines changed: 58 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -16,94 +16,81 @@ SYNOPSIS
1616

1717
DESCRIPTION
1818
-----------
19-
If `<branch>` is specified, `git rebase` will perform an automatic
20-
`git switch <branch>` before doing anything else. Otherwise
21-
it remains on the current branch.
19+
Transplant a series of commits onto a different starting point.
20+
You can also use `git rebase` to reorder or combine commits: see INTERACTIVE
21+
MODE below for how to do that.
2222

23-
If `<upstream>` is not specified, the upstream configured in
24-
`branch.<name>.remote` and `branch.<name>.merge` options will be used (see
25-
linkgit:git-config[1] for details) and the `--fork-point` option is
26-
assumed. If you are currently not on any branch or if the current
27-
branch does not have a configured upstream, the rebase will abort.
28-
29-
All changes made by commits in the current branch but that are not
30-
in `<upstream>` are saved to a temporary area. This is the same set
31-
of commits that would be shown by `git log <upstream>..HEAD`; or by
32-
`git log 'fork_point'..HEAD`, if `--fork-point` is active (see the
33-
description on `--fork-point` below); or by `git log HEAD`, if the
34-
`--root` option is specified.
35-
36-
The current branch is reset to `<upstream>` or `<newbase>` if the
37-
`--onto` option was supplied. This has the exact same effect as
38-
`git reset --hard <upstream>` (or `<newbase>`). `ORIG_HEAD` is set
39-
to point at the tip of the branch before the reset.
40-
41-
[NOTE]
42-
`ORIG_HEAD` is not guaranteed to still point to the previous branch tip
43-
at the end of the rebase if other commands that write that pseudo-ref
44-
(e.g. `git reset`) are used during the rebase. The previous branch tip,
45-
however, is accessible using the reflog of the current branch
46-
(i.e. `@{1}`, see linkgit:gitrevisions[7]).
47-
48-
The commits that were previously saved into the temporary area are
49-
then reapplied to the current branch, one by one, in order. Note that
50-
any commits in `HEAD` which introduce the same textual changes as a commit
51-
in `HEAD..<upstream>` are omitted (i.e., a patch already accepted upstream
52-
with a different commit message or timestamp will be skipped).
53-
54-
It is possible that a merge failure will prevent this process from being
55-
completely automatic. You will have to resolve any such merge failure
56-
and run `git rebase --continue`. Another option is to bypass the commit
57-
that caused the merge failure with `git rebase --skip`. To check out the
58-
original `<branch>` and remove the `.git/rebase-apply` working files, use
59-
the command `git rebase --abort` instead.
60-
61-
Assume the following history exists and the current branch is "topic":
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.
6225

6326
------------
6427
A---B---C topic
6528
/
6629
D---E---F---G master
6730
------------
6831

69-
From this point, the result of either of the following commands:
70-
71-
72-
git rebase master
73-
git rebase master topic
74-
75-
would be:
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`.
7637

7738
------------
7839
A'--B'--C' topic
7940
/
8041
D---E---F---G master
8142
------------
8243

83-
*NOTE:* The latter form is just a short-hand of `git checkout topic`
84-
followed by `git rebase master`. When rebase exits `topic` will
85-
remain the checked-out branch.
8644

87-
If the upstream branch already contains a change you have made (e.g.,
88-
because you mailed a patch which was applied upstream), then that commit
89-
will be skipped and warnings will be issued (if the 'merge' backend is
90-
used). For example, running `git rebase master` on the following
91-
history (in which `A'` and `A` introduce the same set of changes, but
92-
have different committer information):
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:
9348

94-
------------
95-
A---B---C topic
96-
/
97-
D---E---A'---F master
98-
------------
49+
1. Resolve the conflict. You can use `git diff` to find the markers (<<<<<<)
50+
and make edits to resolve the conflict. For each file you edit, you need to
51+
tell Git that the conflict has been resolved. You can mark the conflict as
52+
resolved with `git add <filename>`. After resolving all of the conflicts,
53+
you can continue the rebasing process with
9954
100-
will result in:
55+
git rebase --continue
10156
102-
------------
103-
B'---C' topic
104-
/
105-
D---E---A'---F master
106-
------------
57+
2. Stop the `git rebase` and return your branch to its original state with
58+
59+
git rebase --abort
60+
61+
3. Skip the commit that caused the merge conflict with
62+
63+
git rebase --skip
64+
65+
If you don't specify an `<upstream>` to rebase onto, the upstream configured in
66+
`branch.<name>.remote` and `branch.<name>.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 <upstream>` does:
72+
73+
1. Make a list of all commits on your current branch since it branched
74+
off from `<upstream>` that do not have an equivalent commit in
75+
`<upstream>`.
76+
2. Check out `<upstream>` with the equivalent of
77+
`git checkout --detach <upstream>`.
78+
3. Replay the commits, one by one, in order. This is similar to running
79+
`git cherry-pick <commit>` for each commit. See REBASING MERGES for how merges
80+
are handled.
81+
4. Update your branch to point to the final commit with the equivalent
82+
of `git checkout -B <branch>`.
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 A TOPIC BRANCH WITH --ONTO
93+
----------------------------------------
10794

10895
Here is how you would transplant a topic branch based on one
10996
branch to another, to pretend that you forked the topic branch
@@ -186,28 +173,6 @@ This is useful if F and G were flawed in some way, or should not be
186173
part of topicA. Note that the argument to `--onto` and the `<upstream>`
187174
parameter can be any valid commit-ish.
188175

189-
In case of conflict, `git rebase` will stop at the first problematic commit
190-
and leave conflict markers in the tree. You can use `git diff` to locate
191-
the markers (<<<<<<) and make edits to resolve the conflict. For each
192-
file you edit, you need to tell Git that the conflict has been resolved,
193-
typically this would be done with
194-
195-
196-
git add <filename>
197-
198-
199-
After resolving the conflict manually and updating the index with the
200-
desired resolution, you can continue the rebasing process with
201-
202-
203-
git rebase --continue
204-
205-
206-
Alternatively, you can undo the 'git rebase' with
207-
208-
209-
git rebase --abort
210-
211176
MODE OPTIONS
212177
------------
213178
@@ -253,6 +218,8 @@ As a special case, you may use "A\...B" as a shortcut for the
253218
merge base of A and B if there is exactly one merge base. You can
254219
leave out at most one of A and B, in which case it defaults to HEAD.
255220

221+
See TRANSPLANTING A TOPIC BRANCH WITH --ONTO above for examples.
222+
256223
--keep-base::
257224
Set the starting point at which to create the new commits to the
258225
merge base of `<upstream>` and `<branch>`. Running

0 commit comments

Comments
 (0)