Skip to content

Commit d958894

Browse files
committed
Rewriting history: Minor cleanups; update "git rebase -i" menu
Signed-off-by: Robert P. J. Day <[email protected]>
1 parent 1cb9415 commit d958894

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

book/07-git-tools/sections/rewriting-history.asc

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This can involve changing the order of the commits, changing messages or modifyi
99
In this section, you'll see how to accomplish these tasks so that you can make your commit history look the way you want before you share it with others.
1010

1111
[NOTE]
12+
.Don't push your work until you're happy with it
1213
====
1314
One of the cardinal rules of Git is that, since so much work is local within your clone, you have a great deal of freedom to rewrite your history _locally_.
1415
However, once you push your work, it is a different story entirely, and you should consider pushed work as final unless you have good reason to change it.
@@ -68,8 +69,8 @@ It may be easier to remember the `~3` because you're trying to edit the last thr
6869
$ git rebase -i HEAD~3
6970
----
7071

71-
Remember again that this is a rebasing command every commit included in the range `HEAD~3..HEAD` will be rewritten, whether you change the message or not.
72-
Don't include any commit you've already pushed to a central server doing so will confuse other developers by providing an alternate version of the same change.
72+
Remember again that this is a rebasing command -- every commit included in the range `HEAD~3..HEAD` will be rewritten, whether you change the message or not.
73+
Don't include any commit you've already pushed to a central server -- doing so will confuse other developers by providing an alternate version of the same change.
7374

7475
Running this command gives you a list of commits in your text editor that looks something like this:
7576

@@ -82,12 +83,20 @@ pick a5f4a0d added cat-file
8283
# Rebase 710f0f8..a5f4a0d onto 710f0f8
8384
#
8485
# Commands:
85-
# p, pick = use commit
86-
# r, reword = use commit, but edit the commit message
87-
# e, edit = use commit, but stop for amending
88-
# s, squash = use commit, but meld into previous commit
89-
# f, fixup = like "squash", but discard this commit's log message
90-
# x, exec = run command (the rest of the line) using shell
86+
# p, pick <commit> = use commit
87+
# r, reword <commit> = use commit, but edit the commit message
88+
# e, edit <commit> = use commit, but stop for amending
89+
# s, squash <commit> = use commit, but meld into previous commit
90+
# f, fixup <commit> = like "squash", but discard this commit's log message
91+
# x, exec <command> = run command (the rest of the line) using shell
92+
# b, break = stop here (continue rebase later with 'git rebase --continue')
93+
# d, drop <commit> = remove commit
94+
# l, label <label> = label current HEAD with a name
95+
# t, reset <label> = reset HEAD to a label
96+
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
97+
# . create a merge commit using the original merge commit's
98+
# . message (or the oneline, if no original merge commit was
99+
# . specified). Use -c <commit> to reword the commit message.
91100
#
92101
# These lines can be re-ordered; they are executed from top to bottom.
93102
#
@@ -193,12 +202,20 @@ The script puts helpful instructions in the rebase message:
193202
----
194203
#
195204
# Commands:
196-
# p, pick = use commit
197-
# r, reword = use commit, but edit the commit message
198-
# e, edit = use commit, but stop for amending
199-
# s, squash = use commit, but meld into previous commit
200-
# f, fixup = like "squash", but discard this commit's log message
201-
# x, exec = run command (the rest of the line) using shell
205+
# p, pick <commit> = use commit
206+
# r, reword <commit> = use commit, but edit the commit message
207+
# e, edit <commit> = use commit, but stop for amending
208+
# s, squash <commit> = use commit, but meld into previous commit
209+
# f, fixup <commit> = like "squash", but discard this commit's log message
210+
# x, exec <command> = run command (the rest of the line) using shell
211+
# b, break = stop here (continue rebase later with 'git rebase --continue')
212+
# d, drop <commit> = remove commit
213+
# l, label <label> = label current HEAD with a name
214+
# t, reset <label> = reset HEAD to a label
215+
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
216+
# . create a merge commit using the original merge commit's
217+
# . message (or the oneline, if no original merge commit was
218+
# . specified). Use -c <commit> to reword the commit message.
202219
#
203220
# These lines can be re-ordered; they are executed from top to bottom.
204221
#
@@ -282,7 +299,7 @@ Once again, this changes the SHA-1s of all the commits in your list, so make sur
282299

283300
==== The Nuclear Option: filter-branch
284301

285-
There is another history-rewriting option that you can use if you need to rewrite a larger number of commits in some scriptable way for instance, changing your email address globally or removing a file from every commit.
302+
There is another history-rewriting option that you can use if you need to rewrite a larger number of commits in some scriptable way -- for instance, changing your email address globally or removing a file from every commit.
286303
The command is `filter-branch`, and it can rewrite huge swaths of your history, so you probably shouldn't use it unless your project isn't yet public and other people haven't based work off the commits you're about to rewrite.
287304
However, it can be very useful.
288305
You'll learn a few of the common uses so you can get an idea of some of the things it's capable of.

0 commit comments

Comments
 (0)