In git, what are some good conventions to format multiple comments to a single commit

六眼飞鱼酱① 提交于 2019-12-03 16:09:22

Git has very strong conventions on log messages, but the rules are simple:

  1. First line is a summary of the commit
  2. First line may have a scope description prefix "module:"
  3. Second line is empty
  4. Then follows a discussion in paragraphs, as long as it needs be

As a start you should use these conventions, as the presentation tools even rely on them (The second line being empty is important, and in many situations, you will only see the first line summary.)

With git, commits should be small so the first answer is of course, you shouldn't modify many things in one commit. You should have three commits, not one.

But, you can write a whole essay in the commit log, and there you can describe their changes in all detail (motivation, discarded designs, ideas). If the three changes truly belong together, this text will make it clear why.

I found more instructions describing the same Git Commit message conventions, with examples for which git commands depend on the particular format. (Most of it is all based on an existing convention: Patches sent by emails.)

I have to agree with @kaizer.se. Use git's ability to stage the modifications into 3 different commits. In this way you have a clear idea of what each modification is and your commit comments will give you the why. On a merge back into your main branch (assuming you're using branches for feature mods) you can roll up these smaller commits into one merge.

I strive not to commit changes which require too many comments, but if there's a need for it I usually do something like this:

Multiple changes:

- done this
- fixed that
- removed other

Maybe some additional explanations.

Try to keep your commits atomic, as far as features are concerned. I stage hunks or lines of code for that when I forget to actually commit after every completed feature.

Look here, http://progit.org/book/ch5-2.html, there are commit guidelines and a sample commit.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!