You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/07-git-tools/sections/rewriting-history.asc
+32-15Lines changed: 32 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ This can involve changing the order of the commits, changing messages or modifyi
9
9
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.
10
10
11
11
[NOTE]
12
+
.Don't push your work until you're happy with it
12
13
====
13
14
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_.
14
15
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
68
69
$ git rebase -i HEAD~3
69
70
----
70
71
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.
73
74
74
75
Running this command gives you a list of commits in your text editor that looks something like this:
75
76
@@ -82,12 +83,20 @@ pick a5f4a0d added cat-file
82
83
# Rebase 710f0f8..a5f4a0d onto 710f0f8
83
84
#
84
85
# 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
# . 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.
202
219
#
203
220
# These lines can be re-ordered; they are executed from top to bottom.
204
221
#
@@ -282,7 +299,7 @@ Once again, this changes the SHA-1s of all the commits in your list, so make sur
282
299
283
300
==== The Nuclear Option: filter-branch
284
301
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.
286
303
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.
287
304
However, it can be very useful.
288
305
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