Skip to content

Commit f197ed2

Browse files
peffgitster
authored andcommitted
commit: give advice on empty amend
We generally disallow empty commits with "git commit". The output produced by the wt_status functions is generally sufficient to explain what happened. With --amend commits, however, things are a little more confusing. We would create an empty commit not if you actually have staged changes _now_, but if your staged changes match HEAD^. In this case, it is not immediately obvious why "git commit" claims no changes, but "git status" does not. Furthermore, we should point the user in the direction of git reset, which would eliminate the empty commit entirely. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2543d9b commit f197ed2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

builtin/commit.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ static const char implicit_ident_advice[] =
4848
"\n"
4949
" git commit --amend --author='Your Name <[email protected]>'\n";
5050

51+
static const char empty_amend_advice[] =
52+
"You asked to amend the most recent commit, but doing so would make\n"
53+
"it empty. You can repeat your command with --allow-empty, or you can\n"
54+
"remove the commit entirely with \"git reset HEAD^\".\n";
55+
5156
static unsigned char head_sha1[20];
5257

5358
static char *use_message_buffer;
@@ -693,6 +698,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
693698
if (!commitable && !in_merge && !allow_empty &&
694699
!(amend && is_a_merge(head_sha1))) {
695700
run_status(stdout, index_file, prefix, 0, s);
701+
if (amend)
702+
fputs(empty_amend_advice, stderr);
696703
return 0;
697704
}
698705

0 commit comments

Comments
 (0)