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/03-git-branching/sections/rebasing.asc
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -228,11 +228,13 @@ So what if there was a messy series of merge commits?
228
228
That's how it happened, and the repository should preserve that for posterity.
229
229
230
230
The opposing point of view is that the commit history is the *story of how your project was made.*
231
-
You wouldn't publish the first draft of a book, and the manual for how to maintain your software deserves careful editing.
232
-
This is the camp that uses tools like `rebase` and `filter-branch` to tell the story in the way that's best for future readers.
231
+
You wouldn't publish the first draft of a book, so why show your messy work?
232
+
When you're working on a project, you may need a record of all your missteps and dead-end paths, but when it's time to show your work to the world, you may want to tell a more coherent story of how to get from A to B.
233
+
People in this camp use tools like rebase and filter-branch to rewrite their commits before they're merged into the mainline branch.
234
+
They use tools like `rebase` and `filter-branch`, to tell the story in the way that's best for future readers.
233
235
234
236
Now, to the question of whether merging or rebasing is better: hopefully you'll see that it's not that simple.
235
237
Git is a powerful tool, and allows you to do many things to and with your history, but every team and every project is different.
236
238
Now that you know how both of these things work, it's up to you to decide which one is best for your particular situation.
237
239
238
-
You can get the best of both worlds: rebase local changes before pushing to clean up your work, but never rebase anything that you've pushed somewhere.
240
+
You can get the best of both worlds: rebase local changes before pushing to clean up your work, but never rebase anything that you've pushed somewhere.
Copy file name to clipboardExpand all lines: book/05-distributed-git/sections/contributing.asc
+8-3Lines changed: 8 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,7 @@ Getting in the habit of creating quality commit messages makes using and collabo
60
60
As a general rule, your messages should start with a single line that's no more than about 50 characters and that describes the changeset concisely, followed by a blank line, followed by a more detailed explanation.
61
61
The Git project requires that the more detailed explanation include your motivation for the change and contrast its implementation with previous behavior -- this is a good guideline to follow.
62
62
Write your commit message in the imperative: "Fix bug" and not "Fixed bug" or "Fixes bug."
63
-
Here is a https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[template originally written by Tim Pope]:
63
+
Here is a template you can follow, which we've lightly adapted from one https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[originally written by Tim Pope]:
64
64
65
65
[source,text]
66
66
----
@@ -70,7 +70,7 @@ More detailed explanatory text, if necessary. Wrap it to about 72
70
70
characters or so. In some contexts, the first line is treated as the
71
71
subject of an email and the rest of the text as the body. The blank
72
72
line separating the summary from the body is critical (unless you omit
73
-
the body entirely); tools like rebase can get confused if you run the
73
+
the body entirely); tools like rebase will confuse you if you run the
74
74
two together.
75
75
76
76
Write your commit message in the imperative: "Fix bug" and not "Fixed bug"
@@ -787,6 +787,11 @@ Result: OK
787
787
788
788
==== Summary
789
789
790
-
This section has covered a number of common workflows for dealing with several very different types of Git projects you're likely to encounter, and introduced a couple of new tools to help you manage this process.
790
+
In this section, we covered multiple workflows, and talked about the differences between working as part of a small team on closed-source projects vs contributing to a big public project.
791
+
You know to check for white-space errors before committing, and can write a great commit message.
792
+
You learned how to format patches, and e-mail them to a developer mailing list.
793
+
Dealing with merges was also covered in the context of the different workflows.
794
+
You are now well prepared to collaborate on any project.
795
+
791
796
Next, you'll see how to work the other side of the coin: maintaining a Git project.
792
797
You'll learn how to be a benevolent dictator or integration manager.
Copy file name to clipboardExpand all lines: book/07-git-tools/sections/rewriting-history.asc
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -299,6 +299,27 @@ This changes the SHA-1s of the three most recent commits in your list, so make s
299
299
Notice that the last commit (`f7f3f6d`) in the list is unchanged.
300
300
Despite this commit being shown in the script, because it was marked as ``pick'' and was applied prior to any rebase changes, Git leaves the commit unmodified.
301
301
302
+
==== Deleting a commit
303
+
304
+
If you want to get rid of a commit, you can delete it using the `rebase -i` script.
305
+
In the list of commits, put the word ``drop'' before the commit you want to delete (or just delete that line from the rebase script):
306
+
307
+
[source,console]
308
+
----
309
+
pick 461cb2a This commit is OK
310
+
drop 5aecc10 This commit is broken
311
+
----
312
+
313
+
Because of the way Git builds commit objects, deleting or altering a commit will cause the rewriting of all the commits that follow it.
314
+
The further back in your repo's history you go, the more commits will need to be recreated.
315
+
This can cause lots of merge conflicts if you have many commits later in the sequence that depend on the one you just deleted.
316
+
317
+
If you get partway through a rebase like this and decide it's not a good idea, you can always stop.
318
+
Type `git rebase --abort`, and your repo will be returned to the state it was in before you started the rebase.
319
+
320
+
If you finish a rebase and decide it's not what you want, you can use `git reflog` to recover an earlier version of your branch.
321
+
See <<ch10-git-internals#_data_recovery>> for more information on the `reflog` command.
322
+
302
323
[NOTE]
303
324
====
304
325
Drew DeVault made a practical hands-on guide with exercises to learn how to use `git rebase`.
0 commit comments