Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions book/07-git-tools/sections/rewriting-history.asc
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,27 @@ This changes the SHA-1s of the three most recent commits in your list, so make s
Notice that the last commit (`f7f3f6d`) in the list is unchanged.
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.

==== Deleting a commit

If you want to get rid of a commit, you can delete it using the `rebase -i` script.
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):

[source,console]
----
pick 461cb2a This commit is OK
drop 5aecc10 This commit is broken
----

Because of the way Git builds commit objects, deleting or altering a commit will cause the rewriting of all the commits that follow it.
The further back in your repo's history you go, the more commits will need to be recreated.
This can cause lots of merge conflicts if you have many commits later in the sequence that depend on the one you just deleted.

If you get partway through a rebase like this and decide it's not a good idea, you can always stop.
Type `git rebase --abort`, and your repo will be returned to the state it was in before you started the rebase.

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.
See <<ch10-git-internals#_data_recovery>> for more information on the `reflog` command.

[NOTE]
====
Drew DeVault made a practical hands-on guide with exercises to learn how to use `git rebase`.
Expand Down