Git commit with no commit message

GitMessageCommit

Git Problem Overview


How can I commit changes without specifying commit message? Why is it required by default?

Git Solutions


Solution 1 - Git

git generally requires a non-empty message because providing a meaningful commit message is part of good development practice and good repository stewardship. The first line of the commit message is used all over the place within git; for more, read "A Note About Git Commit Messages".

If you open Terminal.app, cd to your project directory, and git commit -am '', you will see that it fails because an empty commit message is not allowed. Newer versions of git have the
--allow-empty-message commandline argument, including the version of git included with the latest version of Xcode. This will let you use this command to make a commit with an empty message:

git commit -a --allow-empty-message -m ''

Prior to the --allow-empty-message flag, you had to use the commit-tree plumbing command. You can see an example of using this command in the "Raw Git" chapter of the Git book.

Solution 2 - Git

And if you add an alias for it then it's even better right?

git config --global alias.nccommit 'commit -a --allow-empty-message -m ""'

Now you just do an nccommit, nc because of no comment, and everything should be commited.

Solution 3 - Git

When working on an important code update, if you really need an intermediate checkpoint you might just do:

git commit -am'.'

or shorter:

git commit -am.

This adds a commit with the message .

Solution 4 - Git

Note: starting git1.8.3.2 (July 2013), the following command (mentioned above by Jeremy W Sherman) won't open an editor anymore:

git commit --allow-empty-message -m ''

See commit 25206778aac776fc6cc4887653fdae476c7a9b5a:

> If an empty message is specified with the option -m of git commit then the editor is started.
That's unexpected and unnecessary.
Instead of using the length of the message string for checking if the user specified one, directly remember if the option -m was given.


git 2.9 (June 2016) improves the empty message behavior:

See commit 178e814 (06 Apr 2016) by Adam Dinwoodie (me-and).
See commit 27014cb (07 Apr 2016) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 0709261, 22 Apr 2016)

> ## commit: do not ignore an empty message given by -m ''

> - "git commit --amend -m '' --allow-empty-message", even though it looks strange, is a valid request to amend the commit to have no message at all.
Due to the misdetection of the presence of -m on the command line, we ended up keeping the log messsage from the original commit.

  • "git commit -m "$msg" -F file" should be rejected whether $msg is an empty string or not, but due to the same bug, was not rejected when $msg is empty.

  • "git -c template=file -m "$msg"" should ignore the template even when $msg is empty, but it didn't and instead used the contents from the template file.

Solution 5 - Git

--allow-empty-message -m '' (and -m "") fail in Git 2.29.2 on PowerShell:

> error: switch `m' requires a value

(oddly enough, with a backtick on one side and a single quote on the other)


The following works consistently in Linux, PowerShell, and Command Prompt:

git commit --allow-empty-message --no-edit

The --no-edit bit does the trick, as it prevents the editor from launching.

I find this form more explicit and a bit less hacky than forcing an empty message with -m ''.

Solution 6 - Git

Git requires a commit to have a comment, otherwise it wont accept the commit.

You can configure a default template with git as your default commit message or can look up the --allow-empty-message flag in git. I think (not 100% sure) you can reconfigure git to accept empty commit messages (which isn´t such a good idea). Normally each commit should be a bit of work which is described by your message.

Solution 7 - Git

You don't need git to accomplish this. Creative use of a bash function will do the trick just fine. If you don't care about messages, just set a default one and forget it.

function gitcom() {
  git commit -m "my default commit message"
}

If you were feeling really adventurous you could add, commit and push with one command

function gitzap() {
  git add . && git commit -m "whatevs" && git push $1 $2
}

Which you would then run as

gitzap origin master

You could even get deeper and use parse_git_branch to save yourself some keystrokes there, or set a common default of "origin" and "master".

Solution 8 - Git

I have the following config in my private project:

git config alias.auto 'commit -a -m "changes made from [device name]"'

That way, when I'm in a hurry I do

git auto
git push

And at least I know what device the commit was made from.

Solution 9 - Git

I found the simplest solution:

git commit -am'save'

That's all,you will work around git commit message stuff.

you can even save that commend to a bash or other stuff to make it more simple.

Our team members always write those messages,but almost no one will see those message again.

Commit message is a time-kill stuff at least in our team,so we ignore it.

Solution 10 - Git

Building upon some other answers, I came up with the following:

git config --global alias.gromit '!git add --all && git commit --allow-empty-message -m ""'

This differs from the answer by dalvarezmartinez1 in that git add --all also adds new files, while the -a flag in git commit leaves them be. Also, I think that this alias fits the command much better. :-)

Future self, forgive me all the silent, quick, great commits to come.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNikView Question on Stackoverflow
Solution 1 - GitJeremy W. ShermanView Answer on Stackoverflow
Solution 2 - Gitdalvarezmartinez1View Answer on Stackoverflow
Solution 3 - GitlackadaisicalView Answer on Stackoverflow
Solution 4 - GitVonCView Answer on Stackoverflow
Solution 5 - GitDaniel LiuzziView Answer on Stackoverflow
Solution 6 - GitDaniel KurkaView Answer on Stackoverflow
Solution 7 - GitSteven GarciaView Answer on Stackoverflow
Solution 8 - Gite18rView Answer on Stackoverflow
Solution 9 - Gitbronze manView Answer on Stackoverflow
Solution 10 - GitS. Exchange Considered HarmfulView Answer on Stackoverflow