Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to incrementally build commit messages in git?

I'm wondering if it is possible to build git commit messages incrementally, documenting what I'm doing as I make code changes:

  1. Check out and begin work
  2. Enter commit message title (i.e. summary)
  3. Make a code change
  4. Update my commit message to describe change
  5. Repeat 3 and 4 until commit is ready

Is there any mechanism built into git to do this?

like image 501
mtbkrdave Avatar asked Jan 25 '11 22:01

mtbkrdave


People also ask

How do you modify the message of a 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.

How long should git commit messages be?

The ideal size of a git commit summary is around 50 characters in length. Analyzing the average length of commit messages in the Linux kernel suggests this number.


2 Answers

git commit can take a commit message from a file using the -F option. So, you can do something like this:

# Do some work
$ echo 'Did some work' > commit-msg.txt
# Do some more work
$ echo 'Did some more work' >> commit-msg.txt
$ git commit -F commit-msg.txt
like image 99
mipadi Avatar answered Nov 12 '22 20:11

mipadi


You are supposed to do a commit for every small change you do that requires a message. This is especially easy with a distributed versioning system like git that you are using.

  1. Check out and begin work
  2. Make a code change
  3. Enter commit message and commit
  4. Repeat 2 and 3
  5. Push updates

And if you for some reason dislike this pattern and want to do the way you described, just use notepad and append to your message after coding a while and then copy paste it when commiting.

like image 22
skco Avatar answered Nov 12 '22 22:11

skco