Custom Git *Rebase* Commit Message Template

496 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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 .