在 git 中编写长提交消息?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22731126/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:54:43  来源:igfitidea点击:

Writing long commit messages in git?

git

提问by u2908528

I usually write long commit messages in my git bash so that later some one reading my code could easily see what I done.for example in vs2013 in windows form application when designing a form I wrote following.

我通常在我的 git bash 中编写长提交消息,以便稍后阅读我的代码的人可以轻松看到我所做的事情。

git commit -m "Add Name,age ,height,weight and salary labels with corresponding text boxes and more over a Submit Button..."

Problem was when I typed git log --onelineit did not display whole message and chopped off a part of it. My question is that what is the way to write long commit messages in git ,what is the limit and how to display them so that all message could easily be seen on git bash?

问题是当我输入git log --oneline它时,它没有显示完整的信息并截掉了它的一部分。我的问题是在 git 中编写长提交消息的方法是什么,限制是什么以及如何显示它们以便在 git bash 上可以轻松看到所有消息?

采纳答案by u2908528

The way git displays log messages is that it will take the 1st line and use that in git log --oneline, and then anything else is displayed when using the normal git log, as long as there's a blank line between the first and second parts:

git 显示日志消息的方式是它会取第一行并在 中使用它git log --oneline,然后在使用 normal 时显示其他任何内容git log,只要第一部分和第二部分之间有一个空行:

Add summary line here

An example of how to write long commit messages.
Blah blah blah blah blah.
SKADOOSH!

A standard that a lot of people use it to use the first line as a summary of the changes in the commit, and to keep it at a max of 50 characters in length so that it can fit when using git log --oneline --graph. This is actually the standard that the Linux kernel and git project maintainers themselves use (GitHub promotes it as well).

一个标准,很多人使用它来使用第一行作为提交中更改的摘要,并将其长度保持在最多 50 个字符,以便在使用git log --oneline --graph. 这实际上是 Linux 内核和 git 项目维护者自己使用的标准(GitHub 也推广它)。

You might feel that 50 characters is too short though, so another standard that you could use is to keep the summary to a max of 72, 78, or 80 chars.

不过,您可能会觉得 50 个字符太短,因此您可以使用的另一个标准是将摘要保持为最多 72、78 或 80 个字符。

For the rest of the commit message, keeping the max line length to 72, 78, or 80 chars max can also be helpful, like if you often split your monitor screens with a terminal in one half and a browser or editor in the other half. Many editors have shortcuts that will auto-wrap long lines to a max column length for you.

对于提交消息的其余部分,将最大行长度保持为最大 72、78 或 80 个字符也很有帮助,例如,如果您经常将显示器屏幕分为一半,另一半是浏览器或编辑器. 许多编辑器都有快捷方式,可以为您将长行自动换行到最大列长度。

For example, in Sublime Text, the command is ALT+ CMD+ q. Vim also has a few shortcuts to do this (gqis one of them), but you need to configure the max line length for it to work. The same goes for Sublime Text.

例如,在 Sublime Text 中,命令是ALT+ CMD+ q。Vim 也有一些快捷方式可以做到这一点(gq就是其中之一),但是您需要配置最大行长度才能使其工作。Sublime Text 也是如此。