git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/5] git-cherry-pick.txt: do not use 'ORIG_HEAD' in example

From
Philippe Blain <levraiphilippeblain@gmail.com>
Date
Jan 9, 2023, 13:56 UTC
Message-ID
<4525699c-eed5-4da6-b469-b73b87525b23@gmail.com>
In-Reply-To
<xmqqh6x1232e.fsf@gitster.g>
Hi Junio,
Le 2023-01-07 à 21:05, Junio C Hamano a écrit :
Show 16 quoted lines
> "Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
>> The command used in the example to abort the cherry-pick is 'git reset
>> --merge ORIG_HEAD', but cherry-pick does not write 'ORIG_HEAD' before
>> starting its operation.
> 
> Sorry, but I am confused.  Doesn't <1> update ORIG_HEAD used by <3>?
> 
>>  $ git cherry-pick topic^             <1>
>>  $ git diff                           <2>
>> -$ git reset --merge ORIG_HEAD        <3>
>> +$ git cherry-pick --abort            <3>
>>  $ git cherry-pick -Xpatience topic^  <4>
>>  ------------
>>  <1> apply the change that would be shown by `git show topic^`.
> 

No, as far as I was able to test and from my reading of the code, cherry-pick does not write ORIG_HEAD.

Here is a little script that demonstrates this:

``` #!/bin/sh

rm -rf test git -c init.defaultBranch=master init test (

cd test echo hello>file git add file git commit -m initial git branch other echo two>>file git commit -am two git checkout other echo three >>file git commit -am three git checkout master # This writes ORIG_HEAD as 'two' git reset HEAD^ git commit -a -m two-redone # This does not git cherry-pick other # This shows ORIG_HEAD written by reset: echo ORIG_HEAD is: git log --oneline -1 ORIG_HEAD # Whereas HEAD is 'two-redone': echo HEAD is: git log --oneline -1 HEAD ) ```

Looking at the code, 'git grep -p ORIG_HEAD \*.c' reveals the only builtin that write ORIG_HEAD are am, merge, rebase and reset, and the only library code that involves ORIG_HEAD is reset.c::reset_head.

Moreover, 'git grep -p [^a-z_]reset_head \*.c' reveals that the only non-builtin user of reset.c::reset_head is sequencer.c::create_autostash, in which the RESET_ORIG_HEAD flag of 'struct reset_head_opts ropts' is not set.

That is what convinced me that cherry-pick does not write ORIG_HEAD.
Thanks,
Philippe.
Previous: Junio C HamanoNext: Philippe Blain via GitGitGadget
Message 4 of 20 in “Documentation: updates and a correction around 'ORIG_HEAD'”
  1. 0/5 Documentation: updates and a correction around 'ORIG_HEAD'Philippe Blain via GitGitGadget, Jan 7, 2023
  2. 1/5 git-cherry-pick.txt: do not use 'ORIG_HEAD' in examplePhilippe Blain via GitGitGadget, Jan 7, 2023
  3. Junio C HamanoJan 8, 2023
  4. Philippe BlainJan 9, 2023
  5. 2/5 git-reset.txt: mention 'ORIG_HEAD' in the DescriptionPhilippe Blain via GitGitGadget, Jan 7, 2023
  6. 3/5 git-merge.txt: mention 'ORIG_HEAD' in the DescriptionPhilippe Blain via GitGitGadget, Jan 7, 2023
  7. 4/5 revisions.txt: be explicit about commands writing 'ORIG_HEAD'Philippe Blain via GitGitGadget, Jan 7, 2023
  8. Junio C HamanoJan 8, 2023
  9. Philippe BlainJan 9, 2023
  10. 5/5 git-rebase.txt: add a note about 'ORIG_HEAD' being overwrittenPhilippe Blain via GitGitGadget, Jan 7, 2023
  11. Junio C HamanoJan 8, 2023
  12. Philippe BlainJan 9, 2023
  13. 0/5 Documentation: updates and a correction around 'ORIG_HEAD'Philippe Blain via GitGitGadget, Jan 10, 2023
  14. 1/5 git-cherry-pick.txt: do not use 'ORIG_HEAD' in examplePhilippe Blain via GitGitGadget, Jan 10, 2023
  15. 2/5 git-reset.txt: mention 'ORIG_HEAD' in the DescriptionPhilippe Blain via GitGitGadget, Jan 10, 2023
  16. 3/5 git-merge.txt: mention 'ORIG_HEAD' in the DescriptionPhilippe Blain via GitGitGadget, Jan 10, 2023
  17. 4/5 revisions.txt: be explicit about commands writing 'ORIG_HEAD'Philippe Blain via GitGitGadget, Jan 10, 2023
  18. 5/5 git-rebase.txt: add a note about 'ORIG_HEAD' being overwrittenPhilippe Blain via GitGitGadget, Jan 10, 2023
  19. Phillip WoodJan 10, 2023
  20. Junio C HamanoJan 13, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.