Thinking about it some more, older versions of git are expecting to read a null OID in both cases, so we should standardize on that.
Thanks
Phillip
Show 123 quoted lines
> > Thanks
> Wonseok Oh
> > 2026년 11월 23일 (월) 오후 11:32, Phillip Wood <phillip.wood123@gmail.com>님이 작성:
>>
>> Hi Wonseok
>>
>> Thanks for working on this. I think that as an immediate fix for the use
>> of an uninitialized variable the patch looks good, but I'm not sure the
>> behavior of cherry-pick and revert onto an unborn branch makes much sense.
>>
>> On 21/11/2026 06:30, Wonseok Oh via GitGitGadget wrote:
>>> From: Wonseok Oh <marinelay7@gmail.com>
>>>
>>> When picking multiple commits, "git cherry-pick" stores the current HEAD
>>> in .git/sequencer/head for "--abort" to return to. If the branch is
>>> unborn, repo_get_oid() fails and leaves the object ID uninitialized,
>>> but sequencer_pick_revisions() saves it anyway instead of clearing it
>>> to the null OID that sequencer_rollback() checks for to report
>>> "cannot abort from a branch yet to be born".
>>
>> I had a hard time parsing the second half of that sentence.
>> sequencer_rollback() expects us to have saved the null OID when HEAD
>> points to an unborn branch, but instead we save some random junk because
>> we haven't initialized the 'head' variable. The use of an uninitialized
>> variable comes from 0f974e2124 (cherry-pick: allow to pick to unborn
>> branches, 2016-06-06). Before that commit we refused to cherry-pick onto
>> an unborn branch and so did not use 'head' unless it was initialized.
>>
>> It is rather strange that when sequencer_rollback() rejects an unborn
>> branch it refuses to remove the sequencer state so that it is impossible
>> to abort a multi-pick cherry-pick started on an unborn branch. It is
>> also strange that we will try and revert a single commit onto an unborn
>> branch but not multiple commits. 7acaaac275 (revert: allow single-pick
>> in the middle of cherry-pick sequence, 2011-12-10) inserted a separate
>> code path for single picks before the check for an unborn branch, so
>> prior that commit we refused to cherry-pick and revert onto an unborn
>> branch regardless of the number of commits. Going further back in
>> history, the check for an unborn branch was introduced by 04d3d3cfc4
>> (revert: Save data for continuing after conflict resolution,
>> 2011-08-04). The commit message does not mention a reason for
>> introducing that check and therefore changing the behavior but I assume
>> it was to avoid having to support aborting to an unborn branch.
>>
>> It would be nice to either remove the check for an unborn branch when
>> reverting multiple commits, or move the check so that it covers single
>> picks as well. It would also be good to allow the user to abort when
>> cherry-picking onto a unborn branch. Those changes don't need to be part
>> of this series though, they can always come later.
>>
>> I see that rollback_is_safe() expects to see a null OID when picking
>> onto an unborn branch, but update_abort_safety_file() writes an empty
>> file in that case. We should be consistent about the way we represent an
>> unborn branch in the state files. Arguably an empty file is a better way
>> of representing an unborn branch because there is no OID.
>>
>> Thanks
>>
>> Phillip
>>
>>> As a result, "--abort" errors out with "Could not parse object" in my
>>> master build, while in Debian's 2.47.3 build the uninitialized memory
>>> happened to hold the last picked commit's OID and moved the new branch
>>> there.
>>>
>>> Clear the object ID to the null OID when HEAD cannot be resolved, and
>>> add a test.
>>>
>>> Signed-off-by: Wonseok Oh <marinelay7@gmail.com>
>>> ---
>>> sequencer: reset saved HEAD OID when picking onto an unborn branch
>>>
>>> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2317%2Fmarinelay%2Fcherry-pick-unborn-abort-v1
>>> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2317/marinelay/cherry-pick-unborn-abort-v1
>>> Pull-Request: https://github.com/gitgitgadget/git/pull/2317
>>>
>>> sequencer.c | 9 ++++++---
>>> t/t3510-cherry-pick-sequence.sh | 10 ++++++++++
>>> 2 files changed, 16 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/sequencer.c b/sequencer.c
>>> index 4a1c0e70b8..20bfe00ba3 100644
>>> --- a/sequencer.c
>>> +++ b/sequencer.c
>>> @@ -5788,9 +5788,12 @@ int sequencer_pick_revisions(struct repository *r,
>>> goto out;
>>> }
>>>
>>> - if (repo_get_oid(r, "HEAD", &oid) && (opts->action == REPLAY_REVERT)) {
>>> - res = error(_("can't revert as initial commit"));
>>> - goto out;
>>> + if (repo_get_oid(r, "HEAD", &oid)) {
>>> + if (opts->action == REPLAY_REVERT) {
>>> + res = error(_("can't revert as initial commit"));
>>> + goto out;
>>> + }
>>> + oidclr(&oid, r->hash_algo);
>>> }
>>>
>>> if (save_head(oid_to_hex(&oid))) {
>>> diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
>>> index 9400ddfc45..75004bba0c 100755
>>> --- a/t/t3510-cherry-pick-sequence.sh
>>> +++ b/t/t3510-cherry-pick-sequence.sh
>>> @@ -269,6 +269,16 @@ test_expect_success 'allow skipping commit but not abort for a new history' '
>>> test_cmp expect advice
>>> '
>>>
>>> +test_expect_success 'cannot abort a cherry-pick sequence on a new history' '
>>> + pristine_detach initial &&
>>> + git checkout --orphan new_disconnected_seq &&
>>> + git reset --hard &&
>>> + test_must_fail git cherry-pick base..anotherpick &&
>>> + test_must_fail git cherry-pick --abort 2>advice &&
>>> + test_grep "cannot abort from a branch yet to be born" advice &&
>>> + test_must_fail git rev-parse --verify HEAD
>>> +'
>>> +
>>> test_expect_success 'allow skipping stopped cherry-pick because of untracked file modifications' '
>>> test_when_finished "rm unrelated" &&
>>> pristine_detach initial &&
>>>
>>> base-commit: e1ec09b23c8e0deb21a0b95ac5996422277395d4
>>