git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git cherry-pick with --no-verify option
@ 2022-03-14  5:41 Yubin Ruan
  2022-03-14 23:13 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Yubin Ruan @ 2022-03-14  5:41 UTC (permalink / raw)
  To: git

Hi,

Is there any version of Git that supports the cherry-pick command with
"--no-verify"?

It is supported in "git commit" command but not in "git cherry-pick"
command, and I always have to move .git/hooks/pre-commit away to work
around this in case of "git cherry-pick".

Or is there any reason that it is not included in "cherry-pick" command ?

(Please include me in reply since I does not subscribe to the list)

--
Thanks,
Yuibin

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: git cherry-pick with --no-verify option
  2022-03-14  5:41 git cherry-pick with --no-verify option Yubin Ruan
@ 2022-03-14 23:13 ` Junio C Hamano
  2022-03-15  2:29   ` Yubin Ruan
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2022-03-14 23:13 UTC (permalink / raw)
  To: Yubin Ruan; +Cc: git

Yubin Ruan <ablacktshirt@gmail.com> writes:

> Is there any version of Git that supports the cherry-pick command with
> "--no-verify"?
>
> It is supported in "git commit" command but not in "git cherry-pick"
> command, and I always have to move .git/hooks/pre-commit away to work
> around this in case of "git cherry-pick".

Does "git cherry-pick" even trigger pre-commit hook in the first
place?  In my quick tests, it does not seem to.

 $ git init test
 $ cd test
 $ printf "%s\n" '#!/bin/sh' 'echo >&2 no' 'exit 1' >.git/hooks/pre-commit
 $ chmod +x .git/hooks/pre-commit
 $ git commit --allow-empty -m initial
 no

Up to this point, I set up a pre-commit that stops me
unconditionally and made sure it is working.

 $ git commit --no-verify --allow-empty -m initial
 [master (root-commit) 5d967c2] initial
 $ I=$(git rev-parse HEAD)
 $ echo "foo" >file
 $ git add file
 $ git commit --no-verify -m 'add file'
 [master 93a33c4] add file
  1 file changed, 1 insertion(+)
  create mode 100644 file

Then I built two commits

 $ git checkout --detach $I
 HEAD is now at 5d967c2 initial

And rewound to the initial commit so that the second one can be
cherry-picked on top of it.

 $ git cherry-pick master
 [detached HEAD 699c604] add file
  Date: Mon Mar 14 15:58:38 2022 -0700
  1 file changed, 1 insertion(+)
  create mode 100644 file

And that is understandable, as "cherry-pick" is more about replaying
what was committed in the past, with bugs and crufts preserved, than
committing a new-and-improved version out of an existing commit.

Perhaps in a case where a conflict stops the command there is
something?  Let's see.  Continuing from the above transcript:

 $ git cherry-pick master
 HEAD detached from 5d967c2
 You are currently cherry-picking commit 93a33c4.
   (all conflicts fixed: run "git cherry-pick --continue")
   (use "git cherry-pick --skip" to skip this patch)
   (use "git cherry-pick --abort" to cancel the cherry-pick operation)

 nothing to commit, working tree clean
 The previous cherry-pick is now empty, possibly due to conflict resolution.
 If you wish to commit it anyway, use:

     git commit --allow-empty

 Otherwise, please use 'git cherry-pick --skip'
 $ edit file
 $ git commit --allow-empty -a
 no

Of course, "git commit" to conclude a conflicted cherry-pick,
possibly with intervening conflict resolutin by editing working tree
files, would by default trigger pre-commit hook, and it of course
takes --no-verify as expected.

 $ git commit --allow-empty -a --no-verify --no-edit
 [detached HEAD 5858d22] add file
  Date: Mon Mar 14 15:58:38 2022 -0700

Ahh, I think the user is fooled by a bad advice in the message.
(all conflicts fixed: run "git cherry-pick --continue") is wrong and
misleading advice added by those who did not think things through.

After fixing all conflicts, run "git commit" to record it and then
you run "git cherry-pick --continue" if there are more steps to
cherry-pick (i.e. "git cherry-pick A..B").  "git commit" takes not
just "--no-verify" but other options like "--reset-author" to let
you take over authorship if the conflict resolution (actually,
adjusting the original commit to the different context it is being
cherry-picked to) is so involved that a change of authorship is
warranted.  "cherry-pick --continue" does not have all the necessary
flexibility and conceptually it is a separte operation (i.e. "please
continue the stopped sequence" is what it means) from concluding the
current step in the sequence.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: git cherry-pick with --no-verify option
  2022-03-14 23:13 ` Junio C Hamano
@ 2022-03-15  2:29   ` Yubin Ruan
  0 siblings, 0 replies; 3+ messages in thread
From: Yubin Ruan @ 2022-03-15  2:29 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Tue, Mar 15, 2022 at 7:13 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Yubin Ruan <ablacktshirt@gmail.com> writes:
>
> > Is there any version of Git that supports the cherry-pick command with
> > "--no-verify"?
> >
> > It is supported in "git commit" command but not in "git cherry-pick"
> > command, and I always have to move .git/hooks/pre-commit away to work
> > around this in case of "git cherry-pick".
>

<...>

> Ahh, I think the user is fooled by a bad advice in the message.
> (all conflicts fixed: run "git cherry-pick --continue") is wrong and
> misleading advice added by those who did not think things through.
>
> After fixing all conflicts, run "git commit" to record it and then
> you run "git cherry-pick --continue" if there are more steps to
> cherry-pick (i.e. "git cherry-pick A..B").  "git commit" takes not
> just "--no-verify" but other options like "--reset-author" to let
> you take over authorship if the conflict resolution (actually,
> adjusting the original commit to the different context it is being
> cherry-picked to) is so involved that a change of authorship is
> warranted.  "cherry-pick --continue" does not have all the necessary
> flexibility and conceptually it is a separte operation (i.e. "please
> continue the stopped sequence" is what it means) from concluding the
> current step in the sequence.

Yes, in case of conflict when doing cherry-pick, "git commit" should be used
to resolve conflict and then "git cherry-pick --continue" if necessary.
The help message of "git status" in the middle of "git cherry-pick" is quite
misleading.

Thanks~
Yubin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-15  2:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-14  5:41 git cherry-pick with --no-verify option Yubin Ruan
2022-03-14 23:13 ` Junio C Hamano
2022-03-15  2:29   ` Yubin Ruan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).