{"thread":{"id":"11366","subject":"[PATCH] fix git commit --amend -m \"new message\"","startedAt":"2007-12-20T03:23:03Z","lastAt":"2007-12-20T03:23:03Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"63828","messageId":"7v8x3qrqw8.fsf@gitster.siamese.dyndns.org","threadId":"11366","inReplyTo":null,"subject":"[PATCH] fix git commit --amend -m \"new message\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-20T03:23:03Z","receivedAt":"2007-12-20T03:23:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The prepare_log_message() function serves two purposes:\n\n - Prepares the commit log message template, to be given to the end\n   user;\n\n - Return true if there is something committable;\n\n7168624c3530d8c7ee32f930f8fb2ba302b9801f (Do not generate full commit\nlog message if it is not going to be used) cheated to omit the former\nwhen we know the log message template is not going to be used.  However,\nits replacement logic to see if there is something committable was\nbotched.  When amending, it should compare the index with the parent of\nthe HEAD, not the current HEAD.  Otherwise you cannot run --amend to\nfix only the message without changing the tree.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * I think the other cheat to return !!active_nr is checking if it is\n   the initial commit, and its test that appear in the context of this\n   patch should be replaced with \"if (initial_commit)\", but I wanted to\n   first fix the bug.\n\n builtin-commit.c |    6 +++++-\n 1 files changed, 5 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 0a91013..96410de 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -375,6 +375,7 @@ static int prepare_log_message(const char *index_file, const char *prefix)\n \tif (no_edit) {\n \t\tstruct rev_info rev;\n \t\tunsigned char sha1[40];\n+\t\tconst char *parent = \"HEAD\";\n \n \t\tfclose(fp);\n \n@@ -384,9 +385,12 @@ static int prepare_log_message(const char *index_file, const char *prefix)\n \t\tif (get_sha1(\"HEAD\", sha1) != 0)\n \t\t\treturn !!active_nr;\n \n+\t\tif (amend)\n+\t\t\tparent = \"HEAD^1\";\n+\n \t\tinit_revisions(&rev, \"\");\n \t\trev.abbrev = 0;\n-\t\tsetup_revisions(0, NULL, &rev, \"HEAD\");\n+\t\tsetup_revisions(0, NULL, &rev, parent);\n \t\tDIFF_OPT_SET(&rev.diffopt, QUIET);\n \t\tDIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS);\n \t\trun_diff_index(&rev, 1 /* cached */);\n"}]}