Skip to content

Commit c574a27

Browse files
committed
doc: git-rebase: move --onto explanation down
There's a very clear explanation with examples of using --onto which is currently buried in the very long DESCRIPTION section. This moves it to its own section, so that we can reference the explanation from the `--onto` option by name. Signed-off-by: Julia Evans <[email protected]>
1 parent 013a504 commit c574a27

File tree

1 file changed

+87
-81
lines changed

1 file changed

+87
-81
lines changed

Documentation/git-rebase.adoc

Lines changed: 87 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -111,87 +111,6 @@ will result in:
111111
D---E---A'---F master
112112
------------
113113

114-
Here is how you would transplant a topic branch based on one
115-
branch to another, to pretend that you forked the topic branch
116-
from the latter branch, using `rebase --onto`.
117-
118-
First let's assume your 'topic' is based on branch 'next'.
119-
For example, a feature developed in 'topic' depends on some
120-
functionality which is found in 'next'.
121-
122-
------------
123-
o---o---o---o---o master
124-
\
125-
o---o---o---o---o next
126-
\
127-
o---o---o topic
128-
------------
129-
130-
We want to make 'topic' forked from branch 'master'; for example,
131-
because the functionality on which 'topic' depends was merged into the
132-
more stable 'master' branch. We want our tree to look like this:
133-
134-
------------
135-
o---o---o---o---o master
136-
| \
137-
| o'--o'--o' topic
138-
\
139-
o---o---o---o---o next
140-
------------
141-
142-
We can get this using the following command:
143-
144-
git rebase --onto master next topic
145-
146-
147-
Another example of --onto option is to rebase part of a
148-
branch. If we have the following situation:
149-
150-
------------
151-
H---I---J topicB
152-
/
153-
E---F---G topicA
154-
/
155-
A---B---C---D master
156-
------------
157-
158-
then the command
159-
160-
git rebase --onto master topicA topicB
161-
162-
would result in:
163-
164-
------------
165-
H'--I'--J' topicB
166-
/
167-
| E---F---G topicA
168-
|/
169-
A---B---C---D master
170-
------------
171-
172-
This is useful when topicB does not depend on topicA.
173-
174-
A range of commits could also be removed with rebase. If we have
175-
the following situation:
176-
177-
------------
178-
E---F---G---H---I---J topicA
179-
------------
180-
181-
then the command
182-
183-
git rebase --onto topicA~5 topicA~3 topicA
184-
185-
would result in the removal of commits F and G:
186-
187-
------------
188-
E---H'---I'---J' topicA
189-
------------
190-
191-
This is useful if F and G were flawed in some way, or should not be
192-
part of topicA. Note that the argument to `--onto` and the `<upstream>`
193-
parameter can be any valid commit-ish.
194-
195114
MODE OPTIONS
196115
------------
197116

@@ -237,6 +156,8 @@ As a special case, you may use "A\...B" as a shortcut for the
237156
merge base of A and B if there is exactly one merge base. You can
238157
leave out at most one of A and B, in which case it defaults to HEAD.
239158

159+
See TRANSPLANTING A TOPIC BRANCH WITH --ONTO below for examples.
160+
240161
--keep-base::
241162
Set the starting point at which to create the new commits to the
242163
merge base of `<upstream>` and `<branch>`. Running
@@ -1015,6 +936,91 @@ consistent (they compile, pass the testsuite, etc.) you should use
1015936
after each commit, test, and amend the commit if fixes are necessary.
1016937
1017938
939+
TRANSPLANTING A TOPIC BRANCH WITH --ONTO
940+
----------------------------------------
941+
942+
Here is how you would transplant a topic branch based on one
943+
branch to another, to pretend that you forked the topic branch
944+
from the latter branch, using `rebase --onto`.
945+
946+
First let's assume your 'topic' is based on branch 'next'.
947+
For example, a feature developed in 'topic' depends on some
948+
functionality which is found in 'next'.
949+
950+
------------
951+
o---o---o---o---o master
952+
\
953+
o---o---o---o---o next
954+
\
955+
o---o---o topic
956+
------------
957+
958+
We want to make 'topic' forked from branch 'master'; for example,
959+
because the functionality on which 'topic' depends was merged into the
960+
more stable 'master' branch. We want our tree to look like this:
961+
962+
------------
963+
o---o---o---o---o master
964+
| \
965+
| o'--o'--o' topic
966+
\
967+
o---o---o---o---o next
968+
------------
969+
970+
We can get this using the following command:
971+
972+
git rebase --onto master next topic
973+
974+
975+
Another example of --onto option is to rebase part of a
976+
branch. If we have the following situation:
977+
978+
------------
979+
H---I---J topicB
980+
/
981+
E---F---G topicA
982+
/
983+
A---B---C---D master
984+
------------
985+
986+
then the command
987+
988+
git rebase --onto master topicA topicB
989+
990+
would result in:
991+
992+
------------
993+
H'--I'--J' topicB
994+
/
995+
| E---F---G topicA
996+
|/
997+
A---B---C---D master
998+
------------
999+
1000+
This is useful when topicB does not depend on topicA.
1001+
1002+
A range of commits could also be removed with rebase. If we have
1003+
the following situation:
1004+
1005+
------------
1006+
E---F---G---H---I---J topicA
1007+
------------
1008+
1009+
then the command
1010+
1011+
git rebase --onto topicA~5 topicA~3 topicA
1012+
1013+
would result in the removal of commits F and G:
1014+
1015+
------------
1016+
E---H'---I'---J' topicA
1017+
------------
1018+
1019+
This is useful if F and G were flawed in some way, or should not be
1020+
part of topicA. Note that the argument to `--onto` and the `<upstream>`
1021+
parameter can be any valid commit-ish.
1022+
1023+
10181024
RECOVERING FROM UPSTREAM REBASE
10191025
-------------------------------
10201026

0 commit comments

Comments
 (0)