13
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
this post was submitted on 25 May 2026
13 points (100.0% liked)
Git
4672 readers
1 users here now
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Resources
Rules
- Follow programming.dev rules
- Be excellent to each other, no hostility towards users for any reason
- No spam of tools/companies/advertisements. It’s OK to post your own stuff part of the time, but the primary use of the community should not be self-promotion.
Git Logo by Jason Long is licensed under the Creative Commons Attribution 3.0 Unported License.
founded 3 years ago
MODERATORS
Thanks for the 2am nerd snipe :D
You can do this via git hooks and a script. Specifically the prepare-commit-msg hook (
.git/hooks/prepare-commit-msg). In your script, check for the GIT_REFLOG_ACTION env variable, and check if its value is "revert". If so, you are in a revert, and you can echo/printf out whatever you would like in your template.Might be a bit more work to get to where you want, but hopefully that points you in the right direction?
Thanks that is a great start, and even better gives me an excuse to faff about with scripting. I'll share what I come up with!
EDIT Oh interesting, in my debugging I found out that if you revert a revert now (git version 2.43.0) that the subject line reads "Reapply" instead of "Revert "Revert "..."""
Updated OP with what I came up with. I wasn't able to make use of
$GIT_REFLOG_ACTION-- for some reason it was blank in every case, but reading the first line of the existing commit message, if it exists, does the trick.I do foresee a potential problem if you're doing like an interactive rebase for example, and you go to edit a commit message that starts like the default "Revert " style--that could be surprising... Maybe some other cases I haven't thought of too, but yeah, works for me. Thanks for pointing me in the right direction!