blob: f2ef1f7dc093432e8b6c5644cbac5c5e857cb0ca [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-rebase(1)
2=============
3
4NAME
5----
Junio C Hamano7c73c662007-01-19 00:37:506git-rebase - Forward-port local commits to the updated upstream head
Junio C Hamano1a4e8412005-12-27 08:17:237
8SYNOPSIS
9--------
Junio C Hamano9dd8bb02007-02-12 07:15:3510'git-rebase' [-v] [--merge] [-C<n>] [--onto <newbase>] <upstream> [<branch>]
Junio C Hamano1a4e8412005-12-27 08:17:2311
Junio C Hamano6959c6c2006-05-17 10:34:1112'git-rebase' --continue | --skip | --abort
Junio C Hamano6112cad2006-05-02 07:28:0613
Junio C Hamano1a4e8412005-12-27 08:17:2314DESCRIPTION
15-----------
Junio C Hamano6112cad2006-05-02 07:28:0616git-rebase replaces <branch> with a new branch of the same name. When
17the --onto option is provided the new branch starts out with a HEAD equal
18to <newbase>, otherwise it is equal to <upstream>. It then attempts to
19create a new commit for each commit from the original <branch> that does
20not exist in the <upstream> branch.
Junio C Hamano7e9f6b72006-02-22 10:44:5521
Junio C Hamano6112cad2006-05-02 07:28:0622It is possible that a merge failure will prevent this process from being
23completely automatic. You will have to resolve any such merge failure
Junio C Hamano6959c6c2006-05-17 10:34:1124and run `git rebase --continue`. Another option is to bypass the commit
25that caused the merge failure with `git rebase --skip`. To restore the
26original <branch> and remove the .dotest working files, use the command
27`git rebase --abort` instead.
Junio C Hamano6112cad2006-05-02 07:28:0628
29Note that if <branch> is not specified on the command line, the currently
30checked out branch is used.
Junio C Hamano7e9f6b72006-02-22 10:44:5531
32Assume the following history exists and the current branch is "topic":
33
Junio C Hamano6112cad2006-05-02 07:28:0634------------
Junio C Hamano7e9f6b72006-02-22 10:44:5535 A---B---C topic
36 /
37 D---E---F---G master
Junio C Hamano6112cad2006-05-02 07:28:0638------------
Junio C Hamano7e9f6b72006-02-22 10:44:5539
Junio C Hamano2b135272006-03-18 07:45:4240From this point, the result of either of the following commands:
Junio C Hamano7e9f6b72006-02-22 10:44:5541
Junio C Hamano6112cad2006-05-02 07:28:0642
Junio C Hamano7e9f6b72006-02-22 10:44:5543 git-rebase master
44 git-rebase master topic
45
46would be:
47
Junio C Hamano6112cad2006-05-02 07:28:0648------------
Junio C Hamano7e9f6b72006-02-22 10:44:5549 A'--B'--C' topic
50 /
51 D---E---F---G master
Junio C Hamano6112cad2006-05-02 07:28:0652------------
Junio C Hamano7e9f6b72006-02-22 10:44:5553
Junio C Hamanod8c9d432006-11-07 07:19:1354The latter form is just a short-hand of `git checkout topic`
55followed by `git rebase master`.
Junio C Hamano7e9f6b72006-02-22 10:44:5556
Junio C Hamanod8c9d432006-11-07 07:19:1357Here is how you would transplant a topic branch based on one
58branch to another, to pretend that you forked the topic branch
59from the latter branch, using `rebase --onto`.
Junio C Hamano7e9f6b72006-02-22 10:44:5560
Junio C Hamanod8c9d432006-11-07 07:19:1361First let's assume your 'topic' is based on branch 'next'.
62For example feature developed in 'topic' depends on some
63functionality which is found in 'next'.
Junio C Hamano7e9f6b72006-02-22 10:44:5564
Junio C Hamano6112cad2006-05-02 07:28:0665------------
Junio C Hamanod8c9d432006-11-07 07:19:1366 o---o---o---o---o master
67 \
68 o---o---o---o---o next
69 \
70 o---o---o topic
Junio C Hamano6112cad2006-05-02 07:28:0671------------
Junio C Hamano1a4e8412005-12-27 08:17:2372
Junio C Hamanod8c9d432006-11-07 07:19:1373We would want to make 'topic' forked from branch 'master',
74for example because the functionality 'topic' branch depend on
75got merged into more stable 'master' branch, like this:
76
77------------
78 o---o---o---o---o master
79 | \
80 | o'--o'--o' topic
81 \
82 o---o---o---o---o next
83------------
84
85We can get this using the following command:
86
87 git-rebase --onto master next topic
88
89
90Another example of --onto option is to rebase part of a
91branch. If we have the following situation:
92
93------------
94 H---I---J topicB
95 /
96 E---F---G topicA
97 /
98 A---B---C---D master
99------------
100
101then the command
102
103 git-rebase --onto master topicA topicB
104
105would result in:
106
107------------
108 H'--I'--J' topicB
109 /
110 | E---F---G topicA
111 |/
112 A---B---C---D master
113------------
114
115This is useful when topicB does not depend on topicA.
116
Junio C Hamano42f855f2007-02-06 00:09:38117A range of commits could also be removed with rebase. If we have
118the following situation:
119
120------------
121 E---F---G---H---I---J topicA
122------------
123
124then the command
125
126 git-rebase --onto topicA~5 topicA~2 topicA
127
128would result in the removal of commits F and G:
129
130------------
131 E---H'---I'---J' topicA
132------------
133
134This is useful if F and G were flawed in some way, or should not be
135part of topicA. Note that the argument to --onto and the <upstream>
136parameter can be any valid commit-ish.
137
Junio C Hamanof02e09f2006-03-27 07:51:03138In case of conflict, git-rebase will stop at the first problematic commit
Junio C Hamano6112cad2006-05-02 07:28:06139and leave conflict markers in the tree. You can use git diff to locate
140the markers (<<<<<<) and make edits to resolve the conflict. For each
141file you edit, you need to tell git that the conflict has been resolved,
142typically this would be done with
Junio C Hamanof02e09f2006-03-27 07:51:03143
Junio C Hamano6112cad2006-05-02 07:28:06144
145 git update-index <filename>
146
147
148After resolving the conflict manually and updating the index with the
149desired resolution, you can continue the rebasing process with
150
151
152 git rebase --continue
153
Junio C Hamanof02e09f2006-03-27 07:51:03154
155Alternatively, you can undo the git-rebase with
156
Junio C Hamano6112cad2006-05-02 07:28:06157
158 git rebase --abort
Junio C Hamanof02e09f2006-03-27 07:51:03159
Junio C Hamano1a4e8412005-12-27 08:17:23160OPTIONS
161-------
Junio C Hamano7e9f6b72006-02-22 10:44:55162<newbase>::
163Starting point at which to create the new commits. If the
164--onto option is not specified, the starting point is
Junio C Hamano42f855f2007-02-06 00:09:38165<upstream>. May be any valid commit, and not just an
166existing branch name.
Junio C Hamano7e9f6b72006-02-22 10:44:55167
Junio C Hamano1a4e8412005-12-27 08:17:23168<upstream>::
Junio C Hamano42f855f2007-02-06 00:09:38169Upstream branch to compare against. May be any valid commit,
170not just an existing branch name.
Junio C Hamano1a4e8412005-12-27 08:17:23171
Junio C Hamano2b135272006-03-18 07:45:42172<branch>::
Junio C Hamano1a4e8412005-12-27 08:17:23173Working branch; defaults to HEAD.
174
Junio C Hamano6112cad2006-05-02 07:28:06175--continue::
176Restart the rebasing process after having resolved a merge conflict.
177
178--abort::
179Restore the original branch and abort the rebase operation.
180
Junio C Hamano97f518c2006-06-22 19:49:35181--skip::
182Restart the rebasing process by skipping the current patch.
Junio C Hamano97f518c2006-06-22 19:49:35183
184--merge::
185Use merging strategies to rebase. When the recursive (default) merge
186strategy is used, this allows rebase to be aware of renames on the
187upstream side.
188
189-s <strategy>, \--strategy=<strategy>::
190Use the given merge strategy; can be supplied more than
191once to specify them in the order they should be tried.
192If there is no `-s` option, a built-in list of strategies
193is used instead (`git-merge-recursive` when merging a single
194head, `git-merge-octopus` otherwise). This implies --merge.
195
Junio C Hamanofbe00522006-10-19 05:58:48196-v, \--verbose::
197Display a diffstat of what changed upstream since the last rebase.
198
Junio C Hamanod3339982007-02-09 08:38:48199-C<n>::
200Ensure at least <n> lines of surrounding context match before
201and after each change. When fewer lines of surrounding
202context exist they all must match. By default no context is
203ever ignored.
204
Junio C Hamano97f518c2006-06-22 19:49:35205include::merge-strategies.txt[]
206
Junio C Hamano6112cad2006-05-02 07:28:06207NOTES
208-----
209When you rebase a branch, you are changing its history in a way that
210will cause problems for anyone who already has a copy of the branch
211in their repository and tries to pull updates from you. You should
212understand the implications of using 'git rebase' on a repository that
213you share.
214
215When the git rebase command is run, it will first execute a "pre-rebase"
216hook if one exists. You can use this hook to do sanity checks and
217reject the rebase if it isn't appropriate. Please see the template
218pre-rebase hook script for an example.
219
220You must be in the top directory of your project to start (or continue)
221a rebase. Upon completion, <branch> will be the current branch.
222
Junio C Hamano1a4e8412005-12-27 08:17:23223Author
224------
225Written by Junio C Hamano <junkio@cox.net>
226
227Documentation
228--------------
229Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
230
231GIT
232---
233Part of the gitlink:git[7] suite
234