Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't `git cherry-pick` (without `--no-commit`) run my post-commit hook?

How can I trigger a post-commit hook with the command git cherry-pick <commit>?

What I've tried:

  • I tried the command git commit -m '...' . It triggered the post-commit hook normally.
  • In the githooks document, there are no hooks related to cherry-pick.
  • After viewing the source code of Git, I found it uses git merge in some cases, and git commit in others. But I'm not sure when to use which command.

My questions are:

  1. Why don't post-commit hooks work when I use git cherry-pick?
  2. Is there a hook that cherry-pick will run?
like image 490
LongFeida Avatar asked May 18 '21 14:05

LongFeida


People also ask

How do you do cherry pick without commit?

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.

Does cherry pick make a new commit?

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.

How can I commit without pre-commit hook?

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.

How do you push a cherry pick commit?

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 .


Video Answer


1 Answers

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.

like image 54
dan1st Avatar answered Nov 03 '22 00:11

dan1st