tags:

views:

166

answers:

5

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?

+1  A: 

Write it in a file; keep it updated as you work. Include the finalized version when actually committing.

If you're using a graphical frontend for git, then you'll have to specify which so someone can help with it specifically. In general, you can simply paste the message.

Using git from a command line, it will open your editor with a temp file and you can read the message into it (e.g. :r filename in vim).

Or you could use your shell to read that file as the value for the -m parameter:

# bash example, may work elsewhere
git commit -m "$(<filename)"
Roger Pate
-1: This just isn't a good answer IMHO. We all know we could write something down elsewhere beforehand - that's incredibly obvious. Clearly the poster was asking for a feature of git do to what they wanted.
camh
@camh: Git is flexible and doesn't try to take over your entire process. Using your favorite editor when committing *is* a feature of git.
Roger Pate
@camh and yet in a way, that's all perforce is really doing. Since git has the -F flag, you could keep a file for commit messages up to date and just use the -F flag. That is to say, git has special support for it. If you really want, you could even write a git script that edits it for you. All it'd do is call up vi, but it's a pretty darn simple task, so...
siride
@Roger: I understand this, but your answer does not address the question: "Possible with Git?" At they very least you could refer to `git-commit -F` which is very relevant to your answer.
camh
@siride: It's not that simple. I'd expect a staged commit message to be stashed with the index when using git-stash for example. Other operations that affect the index should also similarly affect a staged commit message. This would not happen automatically using files outside git and `-F` with commit.
camh
@camh: If you think you have a better answer, please, post it. I usually prefer to stick to consistent ways in which all of my tools can be used. What's clear to you may not have been clear to the OP, who asked if they are missing something obvious.
Roger Pate
@camh well, just add that file to your git repo to be tracked and the problem is solved.
siride
A: 

Built in, not as far as I know. If you're really desperate though, you could write it in the Terminal like COMMIT="Fix for bug #14453", COMMIT="$COMMIT and bug #4329" then commit like git commit -m "$COMMIT".

46Bit
+5  A: 

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.

fseto
hmm, still understanding the git way of doing things, but this seems to subvert the point of commiting checkpoints, where the last commit is really "commit in progress".
AK
It has the flexibility of doing so. You don't need to use it, but it's there if you need it.
fseto
@AK do it on a private branch and nobody has to know that you are rewriting HEAD
siride
+6  A: 

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.

Abizern
Marking this as the answer since the -t is most like what I was looking for. Interesting to know about the other workflows though, thanks!
AK
A: 

You can use git gui and just leave it open while you work. Write the commit message for the bugfix you're about to do, then do the actual code changes, stage it, and commit it.

MatrixFrog
`git gui` is part of the git suite, thus it's available for all platforms git is available.
FUZxxl
Edited to reflect that. Thanks.
MatrixFrog