Skip to content

Commit 6741aa6

Browse files
bjornggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dbc1b1f commit 6741aa6

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

Documentation/git-rebase.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,17 @@ By replacing the command "pick" with the command "edit", you can tell
368368
the files and/or the commit message, amend the commit, and continue
369369
rebasing.
370370

371+
If you just want to edit the commit message for a commit, replace the
372+
command "pick" with the command "reword".
373+
371374
If you want to fold two or more commits into one, replace the command
372375
"pick" with "squash" for the second and subsequent commit. If the
373376
commits had different authors, it will attribute the squashed commit to
374377
the author of the first commit.
375378

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`.
379382

380383
For example, if you want to reorder the last 5 commits, such that what
381384
was HEAD~4 becomes the new HEAD. To achieve that, you would call

git-rebase--interactive.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,14 @@ do_next () {
340340
pick_one $sha1 ||
341341
die_with_patch $sha1 "Could not apply $sha1... $rest"
342342
;;
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+
;;
343351
edit|e)
344352
comment_for_reflog edit
345353

@@ -752,6 +760,7 @@ first and then run 'git rebase --continue' again."
752760
#
753761
# Commands:
754762
# p, pick = use commit
763+
# r, reword = use commit, but edit the commit message
755764
# e, edit = use commit, but stop for amending
756765
# s, squash = use commit, but meld into previous commit
757766
#

t/lib-rebase.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#
1010
# "[<lineno1>] [<lineno2>]..."
1111
#
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.
1414

1515
set_fake_editor () {
1616
echo "#!$SHELL_PATH" >fake-editor.sh
@@ -32,7 +32,7 @@ cat "$1".tmp
3232
action=pick
3333
for line in $FAKE_LINES; do
3434
case $line in
35-
squash|edit)
35+
squash|edit|reword)
3636
action="$line";;
3737
*)
3838
echo sed -n "${line}s/^pick/$action/p"

t/t3404-rebase-interactive.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,4 +470,18 @@ test_expect_success 'avoid unnecessary reset' '
470470
test 123456789 = $MTIME
471471
'
472472

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+
473487
test_done

0 commit comments

Comments
 (0)