47

How do you git cherry-pick --continue with --no-verify since --no-verify is not a valid option. git cherry-pick --no-commit --continue does not work since those two parameters are mutually exclusive.

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265

8 Answers8

33

If your cherry-pick (without --no-commit) had merge conflicts and you want to --continue after solving them, you can temporarily disable git hooks for the current repo with:

$ git config core.hooksPath # Print current setting
$ git config core.hooksPath '/dev/null/'

After you're done, depending on whether core.hooksPath was set before, you can either restore the previous setting:

$ git config core.hooksPath '/some/previous/path'

or unset it again:

$ git config --unset core.hooksPath
mickdekkers
  • 640
  • 2
  • 11
  • 16
  • 17
    It's unfortunate that this is the only solution – Max Coplan Jan 18 '22 at 23:23
  • 4
    This should be the accepted answer! – knightcool Apr 08 '22 at 05:05
  • 4
    For some reason, the above method didn't work for me (modifying the hooksPath via `git config`). Here's a work-around to the work-around: manually go into your `.git/hooks/` dir, rename the offending hooks, go back and finish the `cherry-pick --continue`, then rename the offending hooks back to their original names. – Erdős-Bacon May 20 '22 at 00:11
  • It is not the first or second time I gladly return to this reply and saves me time. Thankfully I had it bookmarked. – Jonatas CD Jun 09 '23 at 12:17
23

--no-verify is an option for the commit command, not cherry-pick.

However what you can do is to use the --no-commit flag for your cherry-pick, then git commit --no-verify is fine to conclude the cherry-pick.

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • --no-commit does not work with --continue though. I'll add that to the OP to be more clear – Archimedes Trajano Dec 09 '20 at 20:41
  • You don't need `--continue` for the initial `cherry-pick` command. It's only useful after having handled the first cherry-picked commit (and until the sequence is over), to indicate to the sequencer that you're ready to process the next one in your series of commits. – Romain Valeri Dec 09 '20 at 20:45
  • 20
    This approach unfortunately won't work if the `git cherry-pick` induced conflicts that have to be resolved. In that case, after having resolved the conflicts, one only can use `git cherry-pick --continue` to resolve the cherry-pick, however, if the pre-commit hooks fail, one is stuck. The only option is to abort the cherry-pick and restart from scratch, including resolving the merge conflicts. Seems like this is not really what should be happening and there should be a way to disable the hooks temporarily when continuing an active cherry-pick. – Pankrates Aug 09 '21 at 07:46
  • 3
    @Pankrates I used this method on this exact scenario. I cherry-picked a range of commits, a few of the middle ones had conflicts (and were tripping my pre-commit hook). I just fixed the conflicts and did `git add`; `git commit` and then `git cherry-pick --continue` – Halil Sen Mar 18 '22 at 10:11
6

Futher expading @teejay-bruno approach, what I did is:

pre-commit run
git -c core.hooksPath=/dev/null  cherry-pick --continue

This way I still run the verification even if some items fail, and cherry-pick without altering global configuration

hectorcanto
  • 1,987
  • 15
  • 18
3

To expand on @mickdekkers answer, I added the following function to my ~/.bashrc --

git() {
    if [[ $@ == *"--no-verify"* ]];
    then
        command git -c core.hooksPath=/dev/null "$@ | sed 's/--no-verify//'";
    else
        command git "$@";
    fi;
}

This sets the hookpath to null any time the --no-verify flag is used.

tomhughes
  • 4,597
  • 2
  • 24
  • 33
Teejay Bruno
  • 1,716
  • 1
  • 4
  • 11
3

If all conflicts are resolved, then you don't need to git cherry-pick --continue.
Just git commit --no-verify. Then the process will be complete.

Fyta
  • 39
  • 2
  • The cherry-pick continue creates a commit implictly. What you need is also the `--no-commit` flag for the cherry-pick command! – jaques-sam Aug 17 '23 at 11:50
1

Yet another possible workaround would be to stash/un-stash before committing, as this will stop the cherry-pick operation so that the usual commit command can be used:

git stash
git stash pop
git add -u
git status
git commit -n
bandela
  • 116
  • 3
0

Good question. To avoid touching git config or do complex stuff, a trick would be to comment your pre-commit file, then uncomment when cherry-picking is done.

PJ127
  • 986
  • 13
  • 23
0

I just encounter some git conflicts while doing git cherry-pick.

After fixing and git add the required changes, instead of git cherry-pick --continue, run git commit -m "xxx" --no-verify resolve it.

Ying
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 09 '23 at 08:04