Skip to content

Commit 1b1dce4

Browse files
dschogitster
authored andcommitted
Teach rebase an interactive mode
Don't you just hate the fact sometimes, that git-rebase just applies the patches, without any possibility to edit them, or rearrange them? With "--interactive", git-rebase now lets you edit the list of patches, so that you can reorder, edit and delete patches. Such a list will typically look like this: pick deadbee The oneline of this commit pick fa1afe1 The oneline of the next commit ... By replacing the command "pick" with the command "edit", you can amend that patch and/or its commit message, and by replacing it with "squash" you can tell rebase to fold that patch into the patch before that. It is derived from the script sent to the list in <Pine.LNX.4.63.0702252156190.22628@wbgn013.biozentrum.uni-wuerzburg.de> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0cae234 commit 1b1dce4

File tree

5 files changed

+546
-5
lines changed

5 files changed

+546
-5
lines changed

Documentation/git-rebase.txt

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ git-rebase - Forward-port local commits to the updated upstream head
88
SYNOPSIS
99
--------
1010
[verse]
11-
'git-rebase' [-v] [--merge] [-C<n>] [--onto <newbase>] <upstream> [<branch>]
11+
'git-rebase' [-i | --interactive] [-v | --verbose] [--merge] [-C<n>]
12+
[--onto <newbase>] <upstream> [<branch>]
1213
'git-rebase' --continue | --skip | --abort
1314

1415
DESCRIPTION
@@ -208,6 +209,10 @@ OPTIONS
208209
context exist they all must match. By default no context is
209210
ever ignored.
210211

212+
-i, \--interactive::
213+
Make a list of the commits which are about to be rebased. Let the
214+
user edit that list before rebasing.
215+
211216
include::merge-strategies.txt[]
212217

213218
NOTES
@@ -226,9 +231,83 @@ pre-rebase hook script for an example.
226231
You must be in the top directory of your project to start (or continue)
227232
a rebase. Upon completion, <branch> will be the current branch.
228233

229-
Author
234+
INTERACTIVE MODE
235+
----------------
236+
237+
Rebasing interactively means that you have a chance to edit the commits
238+
which are rebased. You can reorder the commits, and you can
239+
remove them (weeding out bad or otherwise unwanted patches).
240+
241+
The interactive mode is meant for this type of workflow:
242+
243+
1. have a wonderful idea
244+
2. hack on the code
245+
3. prepare a series for submission
246+
4. submit
247+
248+
where point 2. consists of several instances of
249+
250+
a. regular use
251+
1. finish something worthy of a commit
252+
2. commit
253+
b. independent fixup
254+
1. realize that something does not work
255+
2. fix that
256+
3. commit it
257+
258+
Sometimes the thing fixed in b.2. cannot be amended to the not-quite
259+
perfect commit it fixes, because that commit is buried deeply in a
260+
patch series. That is exactly what interactive rebase is for: use it
261+
after plenty of "a"s and "b"s, by rearranging and editing
262+
commits, and squashing multiple commits into one.
263+
264+
Start it with the last commit you want to retain as-is:
265+
266+
git rebase -i <after-this-commit>
267+
268+
An editor will be fired up with all the commits in your current branch
269+
(ignoring merge commits), which come after the given commit. You can
270+
reorder the commits in this list to your heart's content, and you can
271+
remove them. The list looks more or less like this:
272+
273+
-------------------------------------------
274+
pick deadbee The oneline of this commit
275+
pick fa1afe1 The oneline of the next commit
276+
...
277+
-------------------------------------------
278+
279+
The oneline descriptions are purely for your pleasure; `git-rebase` will
280+
not look at them but at the commit names ("deadbee" and "fa1afe1" in this
281+
example), so do not delete or edit the names.
282+
283+
By replacing the command "pick" with the command "edit", you can tell
284+
`git-rebase` to stop after applying that commit, so that you can edit
285+
the files and/or the commit message, amend the commit, and continue
286+
rebasing.
287+
288+
If you want to fold two or more commits into one, replace the command
289+
"pick" with "squash" for the second and subsequent commit. If the
290+
commits had different authors, it will attribute the squashed commit to
291+
the author of the last commit.
292+
293+
In both cases, or when a "pick" does not succeed (because of merge
294+
errors), the loop will stop to let you fix things, and you can continue
295+
the loop with `git rebase --continue`.
296+
297+
For example, if you want to reorder the last 5 commits, such that what
298+
was HEAD~4 becomes the new HEAD. To achieve that, you would call
299+
`git-rebase` like this:
300+
301+
----------------------
302+
$ git rebase -i HEAD~5
303+
----------------------
304+
305+
And move the first patch to the end of the list.
306+
307+
Authors
230308
------
231-
Written by Junio C Hamano <[email protected]>
309+
Written by Junio C Hamano <[email protected]> and
310+
Johannes E. Schindelin <[email protected]>
232311

233312
Documentation
234313
--------------

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ SCRIPT_SH = \
204204
git-fetch.sh \
205205
git-ls-remote.sh \
206206
git-merge-one-file.sh git-mergetool.sh git-parse-remote.sh \
207-
git-pull.sh git-rebase.sh \
207+
git-pull.sh git-rebase.sh git-rebase--interactive.sh \
208208
git-repack.sh git-request-pull.sh git-reset.sh \
209209
git-sh-setup.sh \
210210
git-tag.sh git-verify-tag.sh \

0 commit comments

Comments
 (0)