I am trying to find a way to check commits when cherry-picking them. Unfortunately, I cannot find a git hook that works with cherry-pick
operation. What would be a possible solution to execute a script on cherry-picked commit?
As the other told in the comments above, there is no direct cherry-pick hook.
But I can propose you a workaround, that could work under certain conditions:
Some git front-ends add a default commit message to every cherry-pick commit.
Here just as an example GitExtension where a cherry pick command shows you a dialogue called "Cherry pick commit" with a tickable option "Add commit reference to commit message". With this option the commit message will look like e. g.:
Fix of security problem sp345
(cherry picked from commit c157f17740bad0c8c59ff3f693a747552008371d)
# Conflicts:
# authorization/secure/check.py
A commit-msg hook could be written doing this:
- Checking if the commit message contains
cherry picked from commit
- if yes then do whatever you want to do in a "cherry pick hook"
There is only one condition required: That every committer follows the rule to add (via tool or manually) the text to the commit message that is needed to detect it properly as a cherry-picked commit.
© 2022 - 2024 — McMap. All rights reserved.
prepare-commit-msg
is invoked forgit cherry-pick
(with out-n
). But it seems impossible to distinguishgit cherry-pick
from other commands likegit rebase
. – Guyennegit cherry-pick
fromgit rebase
. – Guyenne