Skip to content

Commit abd3fd3

Browse files
committed
Merge branch 'jk/maint-advice-empty-amend' into maint
* jk/maint-advice-empty-amend: commit: give advice on empty amend
2 parents b2a6095 + f197ed2 commit abd3fd3

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;
@@ -699,6 +704,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
699704
if (!commitable && !in_merge && !allow_empty &&
700705
!(amend && is_a_merge(head_sha1))) {
701706
run_status(stdout, index_file, prefix, 0, s);
707+
if (amend)
708+
fputs(empty_amend_advice, stderr);
702709
return 0;
703710
}
704711

0 commit comments

Comments
 (0)