The to-do list command `reword` replays a commit like `pick` but lets
the user also edit the commit's log message. This happens in two
steps. Firstly, the named commit is cherry-picked. Secondly, the
commit created in the first step is amended using an unchanged index
to edit the log message. The pre-commit hook is meant to verify the
changes introduced by a commit (for instance, catching inserted
trailing white space). Since the committed tree is not changed
between the two steps and we do not verify rebased patches, do not
execute the pre-commit hook in the second step.

Specify the git-commit option `--no-pre-commit` to disable the
pre-commit hook when editing the log message. The commit-msg hook
will still be executed to verify the edited commit log message. As
before, if the hook finds the new log message ill-formatted, the
rebase will be interrupted with the unchanged commit replayed and the
new log message in `$GIT_DIR/COMMIT_EDITMSG`.

Add tests.

Signed-off-by: Fabian Ruch <>
---    |  2 +-
 t/ | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/ b/
index 54c4614..570c4e9 100644
--- a/
+++ b/
@@ -504,7 +504,7 @@ do_next () {
                do_pick $sha1 "$rest"
-               output git commit --allow-empty --amend --no-post-rewrite 
${gpg_sign_opt:+"$gpg_sign_opt"} || {
+               output git commit --allow-empty --amend --no-post-rewrite 
--no-pre-commit ${gpg_sign_opt:+"$gpg_sign_opt"} || {
                        warn "Could not amend commit after successfully picking 
$sha1... $rest"
                        exit_with_patch $sha1 1
diff --git a/t/ b/t/
index abb829e..ecdab11 100755
--- a/t/
+++ b/t/
@@ -683,6 +683,13 @@ test_expect_success 'setup failing pre-commit' '
        test_commit --no-verify pre-commit-violated-3
+test_expect_success 'reword a commit violating pre-commit' '
+       git checkout -b reword-violating-pre-commit violating-pre-commit &&
+       test_when_finished reset_rebase &&
+       set_fake_editor &&
+       env FAKE_LINES="reword 1" git rebase -i master
 test_expect_success 'squash commits violating pre-commit' '
        git checkout -b squash-violating-pre-commit violating-pre-commit &&
        test_when_finished reset_rebase &&
@@ -726,6 +733,13 @@ test_expect_success 'rebase a commit violating commit-msg' 
        FAKE_LINES="1" git rebase -i master
+test_expect_success 'reword a commit violating commit-msg' '
+       git checkout -b reword-violating-commit-msg violating-commit-msg &&
+       test_when_finished reset_rebase &&
+       set_fake_editor &&
+       test_must_fail env FAKE_LINES="reword 1" git rebase -i master
 test_expect_success 'squash commits violating commit-msg' '
        git checkout -b squash-violating-commit-msg violating-commit-msg &&
        set_fake_editor &&

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to