How to fill in a blank commit message?

Until a minute ago, I had a Git repository in which the last commit had an empty commit message. I filled it out by crushing the new commit on it with git rebase -i (I was planning to change the contents anyway), but I still would like to know if there is a way to fill in the empty commit messages.

I tried

 git commit --amend 

but it didn’t work, I tried

 git rebase -i HEAD^ 

and a reword . Both attempts led to what Git said

 fatal: commit has empty message 

and go out.

EDIT : to clarify what ended up

 # change some stuff git commit git rebase -i HEAD~2 # squash the last two commits 

but it seems to be a hack.

+6
source share
3 answers

This seems to be a bug that has not yet been fixed (although there are corrections for it). As a workaround, you can provide a message on the command line:

 git commit --amend -m "foo" 
+7
source

Starting git 2.0.1 (June 25, 2014), git will no longer complain about an empty commit message on reboot and trying to put it.

See commit 076cbd6 Jeff King ( peff )

commit : don't complain about empty messages from -C

When we select another commit message, we die() immediately if we find that it is empty, and we won’t start the editor (that is, when running β€œ -C ” instead of β€œ -C ”). <w> However, this check is redundant and harmful.

This is redundant, because we already notice an empty message later, after we start the editor and die there (as for the usual, and not β€œ -C ” case, where the user provided an empty message in the editor).

This is harmful for several reasons:

  • This does not match --allow-empty-message . As a result, git rebase -i cannot select such a commit .
    Thus, you cannot even return in time to fix it with the " reword " or " edit " command.
  • It does not take into account other ways than the editor to modify the message.
    For example, " git commit -C empty-commit -m foo " can take author information from empty-commit, but add a message to it.
    There still needs to be done to make this work correct (and right now we explicitly prohibit " -C with -m "), but this removes one road block.
  • Existing validation is not enough to prevent segfaults.
    We are trying to find in the header " \n\n " the border of the header / body. If it is at the end of the line (i.e., No body), or if we cannot find it at all (i.e., the Truncated commit object), we consider the message empty. With " -C ", that's OK; we die anyway. But with " -C " we continue, and in the case of a truncated commit, dereferencing NULL+2 may end.
+3
source

If you need to change the last commit message (HEAD), use git commit --amend -m 'new message'

 $ git commit --allow-empty --allow-empty-message -m '' [master 5db8236] $ git commit --amend fatal: commit has empty message $ git commit --allow-empty --amend -m 'new message' [master d383d5c] new message 

Keep in mind that I use --allow-empty to force git commit to create an empty commit and --allow-empty-message to force git commit to create a commit with an empty message.

+2
source

Source: https://habr.com/ru/post/915205/


All Articles