blob: 2f417a8f856094b3664eeff2ff3f0ce761c89503 [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 Hamano89d4e0f2007-02-18 00:34:5916If <branch> is specified, git-rebase will perform an automatic
17`git checkout <branch>` before doing anything else. Otherwise
18it remains on the current branch.
19
20All changes made by commits in the current branch but that are not
21in <upstream> are saved to a temporary area. This is the same set
22of commits that would be shown by `git log <upstream>..HEAD`.
23
24The current branch is reset to <upstream>, or <newbase> if the
25--onto option was supplied. This has the exact same effect as
26`git reset --hard <upstream>` (or <newbase>).
27
28The commits that were previously saved into the temporary area are
29then reapplied to the current branch, one by one, in order.
Junio C Hamano7e9f6b72006-02-22 10:44:5530
Junio C Hamano6112cad2006-05-02 07:28:0631It is possible that a merge failure will prevent this process from being
32completely automatic. You will have to resolve any such merge failure
Junio C Hamano6959c6c2006-05-17 10:34:1133and run `git rebase --continue`. Another option is to bypass the commit
34that caused the merge failure with `git rebase --skip`. To restore the
35original <branch> and remove the .dotest working files, use the command
36`git rebase --abort` instead.
Junio C Hamano6112cad2006-05-02 07:28:0637
Junio C Hamano7e9f6b72006-02-22 10:44:5538Assume the following history exists and the current branch is "topic":
39
Junio C Hamano6112cad2006-05-02 07:28:0640------------
Junio C Hamano7e9f6b72006-02-22 10:44:5541 A---B---C topic
42 /
43 D---E---F---G master
Junio C Hamano6112cad2006-05-02 07:28:0644------------
Junio C Hamano7e9f6b72006-02-22 10:44:5545
Junio C Hamano2b135272006-03-18 07:45:4246From this point, the result of either of the following commands:
Junio C Hamano7e9f6b72006-02-22 10:44:5547
Junio C Hamano6112cad2006-05-02 07:28:0648
Junio C Hamano7e9f6b72006-02-22 10:44:5549 git-rebase master
50 git-rebase master topic
51
52would be:
53
Junio C Hamano6112cad2006-05-02 07:28:0654------------
Junio C Hamano7e9f6b72006-02-22 10:44:5555 A'--B'--C' topic
56 /
57 D---E---F---G master
Junio C Hamano6112cad2006-05-02 07:28:0658------------
Junio C Hamano7e9f6b72006-02-22 10:44:5559
Junio C Hamanod8c9d432006-11-07 07:19:1360The latter form is just a short-hand of `git checkout topic`
61followed by `git rebase master`.
Junio C Hamano7e9f6b72006-02-22 10:44:5562
Junio C Hamanod8c9d432006-11-07 07:19:1363Here is how you would transplant a topic branch based on one
64branch to another, to pretend that you forked the topic branch
65from the latter branch, using `rebase --onto`.
Junio C Hamano7e9f6b72006-02-22 10:44:5566
Junio C Hamanod8c9d432006-11-07 07:19:1367First let's assume your 'topic' is based on branch 'next'.
68For example feature developed in 'topic' depends on some
69functionality which is found in 'next'.
Junio C Hamano7e9f6b72006-02-22 10:44:5570
Junio C Hamano6112cad2006-05-02 07:28:0671------------
Junio C Hamanod8c9d432006-11-07 07:19:1372 o---o---o---o---o master
73 \
74 o---o---o---o---o next
75 \
76 o---o---o topic
Junio C Hamano6112cad2006-05-02 07:28:0677------------
Junio C Hamano1a4e8412005-12-27 08:17:2378
Junio C Hamanod8c9d432006-11-07 07:19:1379We would want to make 'topic' forked from branch 'master',
80for example because the functionality 'topic' branch depend on
81got merged into more stable 'master' branch, like this:
82
83------------
84 o---o---o---o---o master
85 | \
86 | o'--o'--o' topic
87 \
88 o---o---o---o---o next
89------------
90
91We can get this using the following command:
92
93 git-rebase --onto master next topic
94
95
96Another example of --onto option is to rebase part of a
97branch. If we have the following situation:
98
99------------
100 H---I---J topicB
101 /
102 E---F---G topicA
103 /
104 A---B---C---D master
105------------
106
107then the command
108
109 git-rebase --onto master topicA topicB
110
111would result in:
112
113------------
114 H'--I'--J' topicB
115 /
116 | E---F---G topicA
117 |/
118 A---B---C---D master
119------------
120
121This is useful when topicB does not depend on topicA.
122
Junio C Hamano42f855f2007-02-06 00:09:38123A range of commits could also be removed with rebase. If we have
124the following situation:
125
126------------
127 E---F---G---H---I---J topicA
128------------
129
130then the command
131
132 git-rebase --onto topicA~5 topicA~2 topicA
133
134would result in the removal of commits F and G:
135
136------------
137 E---H'---I'---J' topicA
138------------
139
140This is useful if F and G were flawed in some way, or should not be
141part of topicA. Note that the argument to --onto and the <upstream>
142parameter can be any valid commit-ish.
143
Junio C Hamanof02e09f2006-03-27 07:51:03144In case of conflict, git-rebase will stop at the first problematic commit
Junio C Hamano6112cad2006-05-02 07:28:06145and leave conflict markers in the tree. You can use git diff to locate
146the markers (<<<<<<) and make edits to resolve the conflict. For each
147file you edit, you need to tell git that the conflict has been resolved,
148typically this would be done with
Junio C Hamanof02e09f2006-03-27 07:51:03149
Junio C Hamano6112cad2006-05-02 07:28:06150
Junio C Hamano89d4e0f2007-02-18 00:34:59151 git add <filename>
Junio C Hamano6112cad2006-05-02 07:28:06152
153
154After resolving the conflict manually and updating the index with the
155desired resolution, you can continue the rebasing process with
156
157
158 git rebase --continue
159
Junio C Hamanof02e09f2006-03-27 07:51:03160
161Alternatively, you can undo the git-rebase with
162
Junio C Hamano6112cad2006-05-02 07:28:06163
164 git rebase --abort
Junio C Hamanof02e09f2006-03-27 07:51:03165
Junio C Hamano1a4e8412005-12-27 08:17:23166OPTIONS
167-------
Junio C Hamano7e9f6b72006-02-22 10:44:55168<newbase>::
169Starting point at which to create the new commits. If the
170--onto option is not specified, the starting point is
Junio C Hamano42f855f2007-02-06 00:09:38171<upstream>. May be any valid commit, and not just an
172existing branch name.
Junio C Hamano7e9f6b72006-02-22 10:44:55173
Junio C Hamano1a4e8412005-12-27 08:17:23174<upstream>::
Junio C Hamano42f855f2007-02-06 00:09:38175Upstream branch to compare against. May be any valid commit,
176not just an existing branch name.
Junio C Hamano1a4e8412005-12-27 08:17:23177
Junio C Hamano2b135272006-03-18 07:45:42178<branch>::
Junio C Hamano1a4e8412005-12-27 08:17:23179Working branch; defaults to HEAD.
180
Junio C Hamano6112cad2006-05-02 07:28:06181--continue::
182Restart the rebasing process after having resolved a merge conflict.
183
184--abort::
185Restore the original branch and abort the rebase operation.
186
Junio C Hamano97f518c2006-06-22 19:49:35187--skip::
188Restart the rebasing process by skipping the current patch.
Junio C Hamano97f518c2006-06-22 19:49:35189
190--merge::
191Use merging strategies to rebase. When the recursive (default) merge
192strategy is used, this allows rebase to be aware of renames on the
193upstream side.
194
195-s <strategy>, \--strategy=<strategy>::
196Use the given merge strategy; can be supplied more than
197once to specify them in the order they should be tried.
198If there is no `-s` option, a built-in list of strategies
199is used instead (`git-merge-recursive` when merging a single
200head, `git-merge-octopus` otherwise). This implies --merge.
201
Junio C Hamanofbe00522006-10-19 05:58:48202-v, \--verbose::
203Display a diffstat of what changed upstream since the last rebase.
204
Junio C Hamanod3339982007-02-09 08:38:48205-C<n>::
206Ensure at least <n> lines of surrounding context match before
207and after each change. When fewer lines of surrounding
208context exist they all must match. By default no context is
209ever ignored.
210
Junio C Hamano97f518c2006-06-22 19:49:35211include::merge-strategies.txt[]
212
Junio C Hamano6112cad2006-05-02 07:28:06213NOTES
214-----
215When you rebase a branch, you are changing its history in a way that
216will cause problems for anyone who already has a copy of the branch
217in their repository and tries to pull updates from you. You should
218understand the implications of using 'git rebase' on a repository that
219you share.
220
221When the git rebase command is run, it will first execute a "pre-rebase"
222hook if one exists. You can use this hook to do sanity checks and
223reject the rebase if it isn't appropriate. Please see the template
224pre-rebase hook script for an example.
225
226You must be in the top directory of your project to start (or continue)
227a rebase. Upon completion, <branch> will be the current branch.
228
Junio C Hamano1a4e8412005-12-27 08:17:23229Author
230------
231Written by Junio C Hamano <junkio@cox.net>
232
233Documentation
234--------------
235Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
236
237GIT
238---
239Part of the gitlink:git[7] suite
240