{"thread":{"id":"11296","subject":"[PATCH] commit: allow --amend to reuse message from another commit","startedAt":"2007-12-14T19:57:22Z","lastAt":"2007-12-14T19:57:22Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"63195","messageId":"7vr6hpqcbh.fsf@gitster.siamese.dyndns.org","threadId":"11296","inReplyTo":null,"subject":"[PATCH] commit: allow --amend to reuse message from another commit","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-14T19:57:22Z","receivedAt":"2007-12-14T19:57:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"After tentatively applying a patch from a contributor, you can get a\nreplacement patch with corrected code and unusable commit log message.\nIn such a case, this sequence ought to give you an editor based on the\nmessage in the earlier commit, to let you describe an incremental\nimprovement:\n\n\tgit reset --hard HEAD^ ;# discard the earlier one\n        git am <corrected-patch\n        git commit --amend -c HEAD@{1}\n\nUnfortunately, --amend insisted reusing the message from the commit\nbeing amended, ignoring the -c option.  This corrects it.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * This was supported in the scripted version if --amend came before -c,\n   but it was broken if the flags were given in the other order.\n\n builtin-commit.c  |    2 +-\n t/t7501-commit.sh |   17 +++++++++++++++++\n 2 files changed, 18 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex ad9f921..518ebe0 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -537,7 +537,7 @@ static int parse_and_validate_options(int argc, const char *argv[],\n \t\tdie(\"Option -m cannot be combined with -c/-C/-F.\");\n \tif (edit_message)\n \t\tuse_message = edit_message;\n-\tif (amend)\n+\tif (amend && !use_message)\n \t\tuse_message = \"HEAD\";\n \tif (use_message) {\n \t\tunsigned char sha1[20];\ndiff --git a/t/t7501-commit.sh b/t/t7501-commit.sh\nindex 05aa97d..d1a415a 100755\n--- a/t/t7501-commit.sh\n+++ b/t/t7501-commit.sh\n@@ -310,4 +310,21 @@ test_expect_success 'same tree (merge and amend merge)' '\n \n '\n \n+test_expect_success 'amend using the message from another commit' '\n+\n+\tgit reset --hard &&\n+\ttest_tick &&\n+\tgit commit --allow-empty -m \"old commit\" &&\n+\told=$(git rev-parse --verify HEAD) &&\n+\ttest_tick &&\n+\tgit commit --allow-empty -m \"new commit\" &&\n+\tnew=$(git rev-parse --verify HEAD) &&\n+\ttest_tick &&\n+\tgit commit --allow-empty --amend -C \"$old\" &&\n+\tgit show --pretty=\"format:%ad %s\" \"$old\" >expected &&\n+\tgit show --pretty=\"format:%ad %s\" HEAD >actual &&\n+\tdiff -u expected actual\n+\n+'\n+\n test_done\n"}]}