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

[PATCH v2 1/2] sequencer: clear saved HEAD OID when picking onto an unborn branch

From
WGWonseok Oh via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 25, 2026, 03:23 UTC
Message-ID
<7c0fe312f161247a5e7192e214e8677547521a92.1795577024.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2317.v2.git.1795577024.gitgitgadget@gmail.com>
From: Wonseok Oh <marinelay7@gmail.com>

When picking multiple commits, "git cherry-pick" saves the current HEAD in .git/sequencer/head so "--abort" can return to it. An unborn branch has no commit to return to, so cherry-pick is expected to save the null OID instead. Only then can sequencer_rollback() refuse "--abort" with "cannot abort from a branch yet to be born".

However, sequencer_pick_revisions() does not handle this case. On an unborn branch, repo_get_oid() fails to resolve HEAD, and the function saves the uninitialized 'oid' to .git/sequencer/head. As a result, "--abort" is not guaranteed to refuse the abort as intended (e.g., the saved 'oid' may point to a random commit, and "--abort" then moves the branch there).

This bug was introduced in 0f974e2124 (cherry-pick: allow to pick to unborn branches, 2016-06-06). Before that, picking onto an unborn branch was refused.

Clear 'oid' with oidclr() when HEAD cannot be resolved, so that the null OID is saved.

Signed-off-by: Wonseok Oh <marinelay7@gmail.com>
---
 sequencer.c                     |  9 ++++++---
 t/t3510-cherry-pick-sequence.sh | 15 +++++++++++++++
 2 files changed, 21 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..d52fda1c54 100755
--- a/t/t3510-cherry-pick-sequence.sh
+++ b/t/t3510-cherry-pick-sequence.sh
@@ -269,6 +269,21 @@ 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 started on an unborn branch' '
+	pristine_detach initial &&
+	git checkout --orphan new_disconnected_seq &&
+	git reset --hard &&
+	test_must_fail git cherry-pick initial picked 2>err &&
+	test_grep "could not apply .* picked" err &&
+	echo $ZERO_OID >expect &&
+	test_cmp expect .git/sequencer/head &&
+	git rev-parse HEAD >expect &&
+	test_must_fail git cherry-pick --abort 2>err &&
+	test_grep "cannot abort from a branch yet to be born" err &&
+	git rev-parse HEAD >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'allow skipping stopped cherry-pick because of untracked file modifications' '
 	test_when_finished "rm unrelated" &&
 	pristine_detach initial &&
-- 
gitgitgadget
Previous: Wonseok Oh via GitGitGadgetNext: Wonseok Oh via GitGitGadget
Message 7 of 8 in “sequencer: reset saved HEAD OID when picking onto an unborn branch”
  1. sequencer: reset saved HEAD OID when picking onto an unborn branchWonseok Oh via GitGitGadget, Nov 21, 2026
  2. Phillip WoodNov 23, 2026
  3. Wonseok OhNov 24, 2026
  4. Phillip WoodNov 24, 2026
  5. Junio C HamanoNov 24, 2026
  6. 0/2 sequencer: save the null OID for an unborn branchWonseok Oh via GitGitGadget, Nov 25, 2026
  7. 1/2 sequencer: clear saved HEAD OID when picking onto an unborn branchWonseok Oh via GitGitGadget, Nov 25, 2026
  8. 2/2 sequencer: save the null OID in abort-safety on an unborn branchWonseok Oh via GitGitGadget, Nov 25, 2026

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.