没有提交消息的 Git 提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6218199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git commit with no commit message
提问by Nik
How can I commit changes without specifying commit message? Why is it required by default?
如何在不指定提交消息的情况下提交更改?为什么默认需要它?
回答by Jeremy W. Sherman
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".
git 通常需要非空消息,因为提供有意义的提交消息是良好开发实践和良好存储库管理的一部分。提交消息的第一行在 git 中到处使用;有关更多信息,请阅读“关于 Git 提交消息的说明”。
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:
如果您打开 Terminal.app,cd
到您的项目目录和git commit -am ''
,您将看到它失败,因为不允许出现空提交消息。较新版本的 git 具有--allow-empty-message
命令行参数,包括最新版本的 Xcode 中包含的 git 版本。这将允许您使用此命令进行带有空消息的提交:
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" chapterof the Git book.
在--allow-empty-message
标志之前,您必须使用commit-tree
管道命令。您可以在 Git 书籍的“原始 Git”一章中看到使用此命令的示例。
回答by dalvarezmartinez1
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.
现在你只做一个 nccommit,nc 因为没有评论,一切都应该被提交。
回答by lackadaisical
When working on an important code update, if you really need an intermediate safepoint you might just do:
在处理重要的代码更新时,如果您确实需要一个中间安全点,您可以这样做:
git commit -am'.'
or shorter:
或更短:
git commit -am.
回答by VonC
Note: starting git1.8.3.2(July 2013), the following command (mentioned aboveby Jeremy W Sherman) won't open an editor anymore:
注意:从 git1.8.3.2(2013 年 7 月)开始,以下命令(上面由Jeremy W Sherman提到)将不再打开编辑器:
git commit --allow-empty-message -m ''
See commit 25206778aac776fc6cc4887653fdae476c7a9b5a:
见提交 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.
如果使用
-m
git commit选项指定了空消息,则启动编辑器。
这是出乎意料和不必要的。
不使用消息字符串的长度来检查用户是否指定了一个,而是直接记住是否-m
给出了选项。
git 2.9 (June 2016) improves the empty message behavior:
git 2.9(2016 年 6 月)改进了空消息行为:
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)
请参阅Adam Dinwoodie( ) 的commit 178e814(2016 年 4 月 6 日)。
请参阅Jeff King ( ) 的commit 27014cb(2016 年 4 月 7 日)。(由Junio C Hamano合并-- --在2016 年 4 月 22 日提交 0709261 中)me-and
peff
gitster
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.
commit
:不要忽略由给出的空消息-m ''
- "
git commit --amend -m '' --allow-empty-message
",尽管看起来很奇怪,但它是将提交修改为完全没有消息的有效请求。
由于错误检测-m
到命令行上的存在,我们最终保留了原始提交的日志消息。- "
git commit -m "$msg" -F file
"无论是否$msg
为空字符串都应该被拒绝,但由于同样的错误,当$msg
为空时不被拒绝。git -c template=file -m "$msg"
即使模板$msg
为空," " 也应该忽略模板,但它没有,而是使用模板文件中的内容。
回答by Steven Garcia
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.
你不需要 git 来完成这个。创造性地使用 bash 函数可以很好地解决问题。如果您不关心消息,只需设置一个默认值并忘记它。
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
}
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".
你甚至可以更深入地使用 parse_git_branch 来保存自己在那里的一些击键,或者设置一个共同的默认值“origin”和“master”。
回答by Daniel Kurka
Git requires a commit to have a comment, otherwise it wont accept the commit.
Git 需要提交才能有评论,否则它不会接受提交。
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.
您可以使用 git 配置默认模板作为默认提交消息,或者可以在 git 中查找 --allow-empty-message 标志。我认为(不是 100% 确定)您可以重新配置 git 以接受空提交消息(这不是一个好主意)。通常,每个提交都应该是您的消息所描述的一些工作。
回答by e18r
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.
至少我知道提交是用什么设备制作的。
回答by bronze man
I found the simplest solution:
我找到了最简单的解决方案:
git commit -am'save'
That's all,you will work around git commit message stuff.
就是这样,您将解决 git commit 消息问题。
you can even save that commend to a bash or other stuff to make it more simple.
您甚至可以将该推荐保存到 bash 或其他东西中以使其更简单。
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.
提交消息至少在我们的团队中是一种消磨时间的东西,所以我们忽略它。
回答by coloradoblue
The commit message is a best practice that should be followed at all times. Unless you're the only developer and that isn't going to change any time soon.
提交消息是一种应始终遵循的最佳实践。除非您是唯一的开发人员,而且这种情况不会很快改变。
git commit -a -m 'asdfasdfadsfsdf'