Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write git commit message before 'git commit'

Tags:

git

I'm learning Git coming from Perforce.

As far as I can tell you must write the commit message in the same step as when you commit. Or am I missing how I might write the message earlier and have it hang around until I'm ready to commit.

I really liked the workflow in perforce where you can edit the changelist description at any time, and then checkin when you're ready. Personally, I like to open the description many times and document as I code, or as I think of noteworthy things to point out.

Possible with Git?

like image 454
ack Avatar asked Sep 19 '10 00:09

ack


People also ask

What should be the first commit message in git?

Usually the first commit is named "Initial commit". As best practice its include a README file describing the project. The README is usually is a md file. You can put any code you wish as well.

How do I leave a commit message in git?

If you are using nano : Press Control+O (the letter, not 0 the number), then Enter to save the message. Then, press Control+X to exit. If you are using vim : Press Escape and then type :wq and press Enter.

Can we commit in git without message?

Git does not recommend to commit without any message. Git commit messages are necessary to look back and see the changes made during a particular commit. If everyone will just commit without any message, no one would ever know what changes a developer has done.


2 Answers

Have a look at the -t <file> flag with git commit

This lets you specify a file to use as the basis for the commit message. The editor is still invoked but at least you can use a commit message which you create in advance.

Alternatively, there is another workflow that you can use with git that might better suit your way of working:

With git you can work on a separate branch from the main line and make lots of small commits with their own messages. Although each of these commits by themselves may not solve the problem that you are working on, they do provide a way of saving the intermediate states of your work with the same sort of messages that you may have been updating in your commit message file.

Once you are ready to commit the sum of your work, you can use the rebase command and squash these commits together. Your editor will then be invoked with the all the individual messages that you used for the smaller commits which you can then edit together into a single message.

This is a lot easier than it sounds here, and is IMHO a more git-like approach.

like image 81
Abizern Avatar answered Sep 24 '22 04:09

Abizern


As long as you haven't push your commit to others, you can do a git commit --amend. This will allow you to modify your commit, as well as your commit message.

I found this really help with the 'commit early and often', without get overwhelm by the number of trivial commits.

like image 44
fseto Avatar answered Sep 22 '22 04:09

fseto