threads / discuss / 25146

Adding a commit message to the index

Subject: Adding a commit message to the index

## tl;dr

4 messages between Sep 18, 2010 and Sep 19, 2010.

replies: 3people: 4as markdown or json

Cameron Hutchison· Sep 18, 2010, 22:38 UTC · lore

Is it possible to add a commit message to the index, and have it used as the final commit message, or as the template for the final commit message?

Witnessing AKPM's ongoing efforts on linux-kernel to get better commit messages out of people, it seems it would be beneficial to be able to stage a commit message and refine it over the course of the development of the commit. The first cut is rarely the best, so being able to refine a commit message as one can refine a commit by incrementally using the index seems like a good idea.

I know I can use git-commit -F and store my commit message outside of git, but it would be nice to have it in the index with the code it comments on. That would make the commit and the message stay together with git-stash for example. Apply this to other index-modifying operations too.

Joshua Juran· Sep 19, 2010, 01:29 UTC · re: Cameron Hutchison · lore

Re: Adding a commit message to the index

On Sep 18, 2010, at 5:48 PM, Cameron Hutchison wrote:
Show 13 quoted lines
> Is it possible to add a commit message to the index, and have it  
> used as
> the final commit message, or as the template for the final commit
> message?
>
> Witnessing AKPM's ongoing efforts on linux-kernel to get better commit
> messages out of people, it seems it would be beneficial to be able to
> stage a commit message and refine it over the course of the  
> development
> of the commit. The first cut is rarely the best, so being able to  
> refine
> a commit message as one can refine a commit by incrementally using the
> index seems like a good idea.

One of the reasons for having a local repo is so you can check in work in progress without committing it to public history.

If you're ready to write a commit message, then make a commit. You can refine it incrementally with `git commit --amend`.

Also, consider making multiple fine-grained commits, and then use interactive rebase to squash them into fewer larger commits (and edit commit messages) as appropriate. It's a lot easier to squash fine commits than to split course ones.

To summarize:  Commit first, answer questions later.
Josh
Ævar Arnfjörð Bjarmason· Sep 19, 2010, 12:19 UTC · re: Cameron Hutchison · lore

Re: Adding a commit message to the index

On Sun, Sep 19, 2010 at 00:48, Cameron Hutchison <lists@xdna.net> wrote:
> Is it possible to add a commit message to the index, and have it used as
> the final commit message, or as the template for the final commit
> message?

What Joshua suggests is better, but you can abuse git-commit by writing a commit message to e.g. .git/MERGE_MSG, then the message will be used at the next 'git commit'.

But just commiting /now/ and squashing/rebasing later is a much better workflow.

Jakub Narebski· Sep 19, 2010, 13:38 UTC · re: Cameron Hutchison · lore

Re: Adding a commit message to the index

Cameron Hutchison <lists@xdna.net> writes:
> Is it possible to add a commit message to the index, and have it used as
> the final commit message, or as the template for the final commit
> message?
[...]
Why not use commit message templates?
-- 
Jakub Narebski
Poland
ShadeHawk on #git

← back to recent threads