Skip to content

Commit c9266d5

Browse files
LostRedSkygitster
authored andcommitted
git-rebase -i: add command "drop" to remove a commit
Instead of removing a line to remove the commit, you can use the command "drop" (just like "pick" or "edit"). It has the same effect as deleting the line (removing the commit) except that you keep a visual trace of your actions, allowing a better control and reducing the possibility of removing a commit by mistake. Signed-off-by: Galan Rémi <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 77bd3ea commit c9266d5

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

Documentation/git-rebase.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,9 @@ rebasing.
514514
If you just want to edit the commit message for a commit, replace the
515515
command "pick" with the command "reword".
516516

517+
To drop a commit, replace the command "pick" with "drop", or just
518+
delete the matching line.
519+
517520
If you want to fold two or more commits into one, replace the command
518521
"pick" for the second and subsequent commits with "squash" or "fixup".
519522
If the commits had different authors, the folded commit will be

git-rebase--interactive.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ Commands:
152152
s, squash = use commit, but meld into previous commit
153153
f, fixup = like "squash", but discard this commit's log message
154154
x, exec = run command (the rest of the line) using shell
155+
d, drop = remove commit
155156
156157
These lines can be re-ordered; they are executed from top to bottom.
157158
@@ -505,7 +506,7 @@ do_next () {
505506
rm -f "$msg" "$author_script" "$amend" || exit
506507
read -r command sha1 rest < "$todo"
507508
case "$command" in
508-
"$comment_char"*|''|noop)
509+
"$comment_char"*|''|noop|drop|d)
509510
mark_action_done
510511
;;
511512
pick|p)

t/lib-rebase.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# specified line.
1515
#
1616
# "<cmd> <lineno>" -- add a line with the specified command
17-
# ("squash", "fixup", "edit", or "reword") and the SHA1 taken
17+
# ("squash", "fixup", "edit", "reword" or "drop") and the SHA1 taken
1818
# from the specified line.
1919
#
2020
# "exec_cmd_with_args" -- add an "exec cmd with args" line.
@@ -46,7 +46,7 @@ set_fake_editor () {
4646
action=pick
4747
for line in $FAKE_LINES; do
4848
case $line in
49-
squash|fixup|edit|reword)
49+
squash|fixup|edit|reword|drop)
5050
action="$line";;
5151
exec*)
5252
echo "$line" | sed 's/_/ /g' >> "$1";;

t/t3404-rebase-interactive.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,4 +1102,22 @@ test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' '
11021102
test $(git cat-file commit HEAD | sed -ne \$p) = I
11031103
'
11041104

1105+
rebase_setup_and_clean () {
1106+
test_when_finished "
1107+
git checkout master &&
1108+
test_might_fail git branch -D $1 &&
1109+
test_might_fail git rebase --abort
1110+
" &&
1111+
git checkout -b $1 master
1112+
}
1113+
1114+
test_expect_success 'drop' '
1115+
rebase_setup_and_clean drop-test &&
1116+
set_fake_editor &&
1117+
FAKE_LINES="1 drop 2 3 drop 4 5" git rebase -i --root &&
1118+
test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1119+
test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1120+
test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1121+
'
1122+
11051123
test_done

0 commit comments

Comments
 (0)