I would like to have bring up the usual editor for a commit message without actually creating a commit after editing. It should propose a message, filled with the usual git status information and a full git diff, which are stripped again after editing. The resulting text is intended to be passed to git commit-tree later on.
So essentially I look for something like
git commit -eF proposed-message.txt -v --cleanup=default
that does not create a commit, but instead spits out the commit message to the standard output or leaves it in a file for later use. It there some git subcommand that can help me with this?
You can use the prepare-commit-msg hook to achieve what you want, by copying the commit message file somewhere and then making the commit fail (exit the hook with a nonzero status). You can run the editor on the file to simulate what git would have done, had the hook not failed (just run $(git var GIT_EDITOR) "$1"; see git-var). Of course you will need to turn this action on and off somehow—perhaps via an environment variable, for instance—so that it does not affect normal commits.
As a general rule, though, this sort of trickiness is a bad idea. See the linked StackOverflow posting in Jubobs' comment.
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