Skip to content

Commit 542ed78

Browse files
committed
Merge branch 'jk/maint-advice-empty-amend'
* jk/maint-advice-empty-amend: commit: give advice on empty amend
2 parents d5cff17 + f197ed2 commit 542ed78

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

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 <you@example.com>'\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;
@@ -708,6 +713,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
708713
if (!commitable && !in_merge && !allow_empty &&
709714
!(amend && is_a_merge(head_sha1))) {
710715
run_status(stdout, index_file, prefix, 0, s);
716+
if (amend)
717+
fputs(empty_amend_advice, stderr);
711718
return 0;
712719
}
713720

0 commit comments

Comments
 (0)