2

So, I know how to set a custom commit message template for git.

However, when I do an interactive rebase and use reword or squash, i would like to be able to set a custom message template for those commits as well.

So far, I haven't been able to find how to do this.

tiennou
  • 487
  • 3
  • 13
Multifarious
  • 216
  • 1
  • 5
  • The reword and squash operations always start with the original commit message, so they don't really "call for" templates. In the old rebase code (written in shell script) you could easily hack this, but now that rebase is being rewritten in C it's more difficult. – torek Aug 01 '17 at 16:31
  • torek do you know of a way to append anything to the bottom of the template (so after the # Please enter the commit message... lines)? I just need to show our commit styleguide at the bottom. – Multifarious Aug 01 '17 at 16:33
  • I don't think there is one. If your Git is older and still uses the shell script, look at `$(git --exec-path)/git-rebase--interactive` and find where it builds the squash message for editing, and modify that. If your Git is newer, download the source to Git and modify that, then build and install a new Git. The Git source is kept in (what else?) Git and there is a read-only repository available at http://github.com/git/git/ – torek Aug 01 '17 at 16:44

1 Answers1

1

There's a few options, depending on what you're after — git throws quite a bunch of text buffers at you when you perform an interactive rebase.

Customizing the todo list generation (a.k.a .git/rebase-$mode/todo-list) can be done via a couple configuration keys :

  • rebase.missingCommitsCheck controls git's reporting behavior when commit hashes are removed from the todo-list. Default is ignore, but warn and error are supported.

  • rebase.abbreviateCommands controls whether git will prefer the "shorthand syntax" for rebase operations (eg. p, f, instead of pick, fixup, etc.).

  • rebase.instructionFormat controls the todo-list generation itself.

If you want to customize the commit message itself while the rebase has been started, when you've asked for it (ie. on a reword, squash, or fixup operation), then you're likely after git commit --verbose, or its config variant, which you can set globally using

git config --global --bool commit.verbose true

As a "last resort", it's also possible to enable the .git/hooks/prepare-commit-msg hook and tweak its behavior, but IMHO it's more finicky .

tiennou
  • 487
  • 3
  • 13