@matheusbsbs / matheus-bagliano / commits / 6741aa6c39
Fork 0

Teach 'rebase -i' the command "reword"

Make it easier to edit just the commit message for a commit using 'git rebase -i' by introducing the "reword" command. Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Björn Gustavsson committed Oct 7, 2009 at 08:13 UTC 6741aa6c399dec3d8f0b25699a73b8fcf974d702
4 files changed +32 -6
Documentation/git-rebase.txt
+6 -3
@@ -368,14 +368,17 @@ By replacing the command "pick" with the command "edit", you can tell
368 the files and/or the commit message, amend the commit, and continue
369 rebasing.
370
371 +If you just want to edit the commit message for a commit, replace the
372 +command "pick" with the command "reword".
373 +
374 If you want to fold two or more commits into one, replace the command
375 "pick" with "squash" for the second and subsequent commit. If the
376 commits had different authors, it will attribute the squashed commit to
377 the author of the first commit.
378
376 -In both cases, or when a "pick" does not succeed (because of merge
377 -errors), the loop will stop to let you fix things, and you can continue
378 -the loop with `git rebase --continue`.
379 +'git-rebase' will stop when "pick" has been replaced with "edit" or
380 +when a command fails due to merge errors. When you are done editing
381 +and/or resolving conflicts you can continue with `git rebase --continue`.
382
383 For example, if you want to reorder the last 5 commits, such that what
384 was HEAD~4 becomes the new HEAD. To achieve that, you would call
git-rebase--interactive.sh
+9
@@ -340,6 +340,14 @@ do_next () {
340 pick_one $sha1 ||
341 die_with_patch $sha1 "Could not apply $sha1... $rest"
342 ;;
343 + reword|r)
344 + comment_for_reflog reword
345 +
346 + mark_action_done
347 + pick_one $sha1 ||
348 + die_with_patch $sha1 "Could not apply $sha1... $rest"
349 + output git commit --amend
350 + ;;
351 edit|e)
352 comment_for_reflog edit
353
@@ -752,6 +760,7 @@ first and then run 'git rebase --continue' again."
760 #
761 # Commands:
762 # p, pick = use commit
763 +# r, reword = use commit, but edit the commit message
764 # e, edit = use commit, but stop for amending
765 # s, squash = use commit, but meld into previous commit
766 #
t/lib-rebase.sh
+3 -3
@@ -9,8 +9,8 @@
9 #
10 # "[<lineno1>] [<lineno2>]..."
11 #
12 -# If a line number is prefixed with "squash" or "edit", the respective line's
13 -# command will be replaced with the specified one.
12 +# If a line number is prefixed with "squash", "edit", or "reword", the
13 +# respective line's command will be replaced with the specified one.
14
15 set_fake_editor () {
16 echo "#!$SHELL_PATH" >fake-editor.sh
@@ -32,7 +32,7 @@ cat "$1".tmp
32 action=pick
33 for line in $FAKE_LINES; do
34 case $line in
35 - squash|edit)
35 + squash|edit|reword)
36 action="$line";;
37 *)
38 echo sed -n "${line}s/^pick/$action/p"
t/t3404-rebase-interactive.sh
+14
@@ -470,4 +470,18 @@ test_expect_success 'avoid unnecessary reset' '
470 test 123456789 = $MTIME
471 '
472
473 +test_expect_success 'reword' '
474 + git checkout -b reword-branch master &&
475 + FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
476 + git show HEAD | grep "E changed" &&
477 + test $(git rev-parse master) != $(git rev-parse HEAD) &&
478 + test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
479 + FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
480 + git show HEAD^ | grep "D changed" &&
481 + FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
482 + git show HEAD~3 | grep "B changed" &&
483 + FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
484 + git show HEAD~2 | grep "C changed"
485 +'
486 +
487 test_done