tags:

views:

47

answers:

2

Hi everyone,

I use git for my local work (and love it ever so much), and I follow a workflow similar to the one described in this article. So basically, when starting on a new feature, I create a branch for it, go through the usual hack then commit cycle, and when I think I'm done with it, I squash it into a single commit using git rebase --interactive master, and I always end up editing the multitude of commit messages into something looking like the example in the article, reproduced here:

[#3275] User Can Add A Comment To a Post

* Adding Comment model, migrations, spec
* Adding Comment controller, helper, spec
* Adding Comment relationship with Post
* Comment belongs to a User
* Comment form on Post show page

Of course, that's after a bunch of removing # This is the xth commit message lines and copy/pasting * in front of each commit message.

Now, what I was wondering, is there any way to customize how git rebase -i outputs the merged commit messages so I don't have to do all that hacking?

(I use msysgit, if that matters. My editor is Notepad++.)

Thanks!

+2  A: 

There's no way (short of hacking the source) to modify the squash message template, I don't think. However, you have a couple options:

  • Use a git log command to get the shortlist, something like `git log --pretty="* %s" commit-1..commit-2 to get you your bullets. In linux it's very possible to do this from within your editor - don't know how that works with msysgit.

  • Have your editor do the work for you! I don't know what your editor is, so I can't really tell you what to do, but it'd certainly be very possible in vim. (The idea being: search for /# This is the .* commit message/, delete a couple lines, keep one, delete up to the next comment)

Also, it's not what you want in this case, probably, but in fairly recent versions of git, there's a fixup identifier that you can use instead of squash - it does the same thing, but it discards the commit message, so if you have one commit with the real message then ten fixes, you can just mark them all fixup and not have to delete their throwaway messages.

Jefromi
I agree. +1. For more on fixup (and autosquashing), see http://stackoverflow.com/questions/2302736/trimming-git-checkins/2302947#2302947
VonC
Cool! I'll have to update msysgit and give this fixup and such a shot. :)
adamjford
I've started to use Vim for my text editing shenanigans, so I suppose I'm going with door #2!
adamjford
A: 

You can made a --amend when you want. You can checkout in commit previous you commit you want change and amend it.

shingara
Yup, and I use --amend quite a bit because I have fat fingers, apparently. :) But I don't need to --amend my squashed commits to edit the resulting commit message; I just format it in the text editor that pops up after you assign pick/edit/squash to each commit. I clarified my question to account for this.
adamjford