How can I trigger a post-commit hook with the command git cherry-pick <commit>
?
What I've tried:
git commit -m '...'
. It triggered the post-commit hook normally.git merge
in some cases, and git commit
in others. But I'm not sure when to use which command.My questions are:
git cherry-pick
?The --no-commit option will execute the cherry pick but instead of making a new commit it will move the contents of the target commit into the working directory of the current branch.
The git cherry-pick is a very useful command. It takes changes from a specific commit and applies them to your current branch in a new commit. As a consequence, git cherry pick does not alter your current Git history : instead it adds commits to it.
Creates a new commit skipping the pre-commit and commit-msg hooks. Use git commit --no-verify -m <message> to commit staged changes without running git hooks.
Beside git commit --amend , you can also use git cherry-pick <commit-hash> -n && git commit . -n instructs git cherry-pick to apply the changes only and not to create the commit. You can specify the commit message in the subsequent git commit .
Why don't post-commit hooks work when I use
git cherry-pick
?
The post-commit
hook is run after creating a commit.
However, cherry-pick does not really create a new commit with new information (from the user perspective) but copies another commit.
Is there a hook that cherry-pick will run?
Yes, the prepare-commit-msg should be run before commit is cherry-picked, even though the commit-msg
hook is not executed.
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