Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

dvcs

I was wondering how people normally separate out the multiple comments in a single commit. Stars? Commas? Separate lines? Just wondering what you find to be the best.

I'm using this now when I add comments via Emacs, but not sure I like it:

Added error messaging
Cleaned up sign-up UI
Added recaptcha

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Committer: Conrad Chu <[email protected]>
#
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   app/controllers/api_controller.rb
#       modified:   app/controllers/users_controller.rb
#       modified:   app/models/user.rb
#       modified:   app/views/users/new.html.erb
#       modified:   app/views/users/show.html.erb
#       modified:   config/environment.rb
#       modified:   db/migrate/20090923001219_create_users.rb
#       modified:   db/schema.rb
#       modified:   doc/README
#       modified:   public/stylesheets/master.css
#       new file:   vendor/plugins/recaptcha/.gitignore
#       new file:   vendor/plugins/recaptcha/CHANGELOG
like image 352
chuboy Avatar asked Oct 02 '09 22:10

chuboy


People also ask

How many different changes should be in a single commit?

One of these responsibilities is taking care of how changes are inserted into the VCS, creating a commit which purpose should reflect one change and one change only. Also known as an atomic change.

How do I add a comment to a git commit?

On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter. In your text editor, edit the commit message, and save the commit. You can add a co-author by adding a trailer to the commit.

How do you commit multiple texts?

Another method of adding a multi-line Git commit message is using quotes with your message, though it depends on your shell's capacity. To do this, add single or double quotes before typing the message, keep pressing enter and writing the next line, and finally close the quote at end of the message.


2 Answers

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.)

like image 68
u0b34a0f6ae Avatar answered Oct 14 '22 08:10

u0b34a0f6ae


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.

like image 41
Lou Avatar answered Oct 14 '22 10:10

Lou