Skip to content

Commit 2929e7c

Browse files
committed
Create section: drop commit with git rebase -i
Fixes #824
1 parent 58e65f7 commit 2929e7c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,34 @@ This changes the SHA-1s of the three most recent commits in your list, so make s
299299
Notice that the last commit (`f7f3f6d`) in the list is unchanged.
300300
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.
301301

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:
306+
307+
[source,console]
308+
----
309+
pick 461cb2a This commit is OK
310+
drop 5aecc10 This commit is broken
311+
----
312+
313+
[CAUTION]
314+
====
315+
Do not delete/drop a commit that other commits depend on!
316+
It's a bad idea to drop the first commit in the `rebase -i` script list.
317+
The following commits depend on the first commit being present, as the root of all changes that follow.
318+
====
319+
320+
Avoid doing this:
321+
[source,console]
322+
----
323+
drop 5aecc10 This commit is broken
324+
pick c6be4c9 This commit is OK but depends on changes made in 5aecc10
325+
----
326+
327+
Git will complain about the broken state, and ask you to resolve the conflicts manually.
328+
You can also just back out of the rebase by using `git rebase --abort`.
329+
302330
[NOTE]
303331
====
304332
Drew DeVault made a practical hands-on guide with exercises to learn how to use `git rebase`.

0 commit comments

Comments
 (0)