git help commit
says the following:
--cleanup=<mode>
This option determines how the supplied commit message should be
cleaned up before committing. The <mode> can be strip, whitespace,
verbatim, or default.
strip
Strip leading and trailing empty lines, trailing whitespace,
and #commentary and collapse consecutive empty lines.
whitespace
Same as strip except #commentary is not removed.
verbatim
Do not change the message at all.
default
Same as strip if the message is to be edited. Otherwise
whitespace.
I'd like to determine which cleanup mode is going to be applied from the commit-msg hook (correctly using the commit.cleanup
config value when necessary). I run some validations on my commit messages and I want to make sure I'm seeing exactly what Git is planning on using.
Alternatively, I'll accept a way to grab the commit message text post-cleanup (maybe I can trick Git into cleaning it up for me?). This would be great for my use case, since then I wouldn't have to worry about re-implementing any cleanup modes.
Commit has not been pushed online On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter. In your text editor, edit the commit message, and save the commit.
Changing the latest Git commit message If the message to be changed is for the latest commit to the repository, then the following commands are to be executed: git commit --amend -m "New message" git push --force repository-name branch-name.
Unfortunately, in current(ish) git source, the cleanup mode is not passed through to the hook in any way. The argument to --cleanup
is stored only in the (static
, local to builtin/commit.c
) variable cleanup_mode
and not exported (e.g., as an argument or environment variable) to the various hooks.
(It should be easy to add an environment variable containing the setting. If you want to experiment with this yourself, see builtin/commit.c
function parse_and_validate_options
; put in a call to setenv()
with appropriate arguments.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With