Skip to content

Commit

Permalink
fix git commit --amend -m "new message"
Browse files Browse the repository at this point in the history
The prepare_log_message() function serves two purposes:

 - Prepares the commit log message template, to be given to the end
   user;

 - Return true if there is something committable;

7168624 (Do not generate full commit
log message if it is not going to be used) cheated to omit the former
when we know the log message template is not going to be used.  However,
its replacement logic to see if there is something committable was
botched.  When amending, it should compare the index with the parent of
the HEAD, not the current HEAD.  Otherwise you cannot run --amend to
fix only the message without changing the tree.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Dec 20, 2007
1 parent 885ed37 commit fbcf118
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion builtin-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ static int prepare_log_message(const char *index_file, const char *prefix)
if (no_edit) {
struct rev_info rev;
unsigned char sha1[40];
const char *parent = "HEAD";

fclose(fp);

Expand All @@ -384,9 +385,12 @@ static int prepare_log_message(const char *index_file, const char *prefix)
if (get_sha1("HEAD", sha1) != 0)
return !!active_nr;

if (amend)
parent = "HEAD^1";

init_revisions(&rev, "");
rev.abbrev = 0;
setup_revisions(0, NULL, &rev, "HEAD");
setup_revisions(0, NULL, &rev, parent);
DIFF_OPT_SET(&rev.diffopt, QUIET);
DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS);
run_diff_index(&rev, 1 /* cached */);
Expand Down

0 comments on commit fbcf118

Please sign in to comment.