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

Re: [PATCH 2/3] sequencer: remove REBASE_HEAD at the end of a rebase

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 27, 2026, 20:10 UTC
Message-ID
<xmqqh5i6j462.fsf@gitster.g>
In-Reply-To
<ba13c74698d2af3bd2ababbf2ff1a9738a81d501.1793098652.git.phillip.wood@dunelm.org.uk>
Phillip Wood <phillip.wood123@gmail.com> writes:
> Several existing tests are extended to check that REBASE_HEAD is
> present when we stop for conflicts and is absent when the rebase
> finishes.
Good.
Show 34 quoted lines
> diff --git a/sequencer.c b/sequencer.c
> index 2ac78e15b89..2d6a5f525c7 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -1781,7 +1781,10 @@ static int do_commit(struct repository *r,
>  		if (is_rebase_i(opts) && oid)
>  			if (write_rebase_head(oid))
>  			    return -1;
> -		return run_git_commit(msg_file, reflog_action, opts, flags);
> +		res = run_git_commit(msg_file, reflog_action, opts, flags);
> +		if (!res && is_rebase_i(opts) && oid)
> +			refs_delete_ref(get_main_ref_store(r), "", "REBASE_HEAD",
> +					NULL, REF_NO_DEREF);
>  	}
>  
>  	return res;
> @@ -5178,6 +5181,8 @@ static int pick_commits(struct repository *r,
>  	unlink(rebase_path_amend());
>  	unlink(rebase_path_patch());
>  	unlink(git_path_merge_labels(r));
> +	refs_delete_ref(get_main_ref_store(r), "", "REBASE_HEAD", NULL,
> +			REF_NO_DEREF);
>  
>  	while (todo_list->current < todo_list->nr) {
>  		struct todo_item *item = todo_list->items + todo_list->current;
> @@ -5206,8 +5211,6 @@ static int pick_commits(struct repository *r,
>  			unlink(git_path_merge_head(r));
>  			refs_delete_ref(get_main_ref_store(r), "", "AUTO_MERGE",
>  					NULL, REF_NO_DEREF);
> -			refs_delete_ref(get_main_ref_store(r), "", "REBASE_HEAD",
> -					NULL, REF_NO_DEREF);
>  
>  			if (item->command == TODO_BREAK) {
>  				if (!opts->verbose)

The patch is a bit dense (not a fault of the patch, but the blame largely lies on the overly long functions involved with multi-level callchain), but the idea is that the existing removal in the loop inside pick_commits() may not trigger if the user resumes (via "--continue" or "--skip") with an exhausted todo_list and that would leave the REBASE_HEAD file behind, so we remove at the beginning of pick_commits() before entering the loop, and also in do_commit(), which is called deep inside the callchain from the loop to handle one step, immediately before it returns on successful commit.

Which makes perfect sense. The new tests seems to cover these cases adequately, too.

Thanks.
Previous: Phillip WoodNext: Phillip Wood
Message 5 of 7 in “sequencer: fix cleanup of REBASE_HEAD and AUTO_MERGE”
  1. 0/3 sequencer: fix cleanup of REBASE_HEAD and AUTO_MERGEPhillip Wood, Oct 27, 2026
  2. 1/3 test_ref_missing(): improve error messagePhillip Wood, Oct 27, 2026
  3. Junio C HamanoOct 27, 2026
  4. 2/3 sequencer: remove REBASE_HEAD at the end of a rebasePhillip Wood, Oct 27, 2026
  5. Junio C HamanoOct 27, 2026
  6. 3/3 sequencer: remove AUTO_MERGE at the end of a rebasePhillip Wood, Oct 27, 2026
  7. Junio C HamanoOct 27, 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.