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

Re: [PATCH] history: refuse to rewrite branches used by other worktrees

From
AGAniket Gupta <aniketgupta3001@gmail.com>
Date
Nov 23, 2026, 21:54 UTC
Message-ID
<20261123215424.27553-1-aniketgupta3001@gmail.com>
In-Reply-To
<xmqqa4mz5mr8.fsf@gitster.g>
Thanks for taking a look!
> And is_bare_repository() is true.  We skip update_worktree() and
> update the 'main' branch via its HEAD, making the index and the
> worktree of the worktree at ../wt out of sync, no?

True. I am able to repro this. In a bare repo nobody has the branch that HEAD points to checked out, but the check skips it as if the current worktree did. So "git history drop" moves "main" and ../wt shows the changes of the dropped commit as staged.

> Perhaps head_target should be initialized to NULL and assigned the
> resolution result of HEAD only in a non-bare repository, or something?

I think that would fix it. In v2 I'd like to go a bit further though: ask the other worktrees if they use the current branch instead of skipping it by name. That also covers a bare repo and a branch that two worktrees have checked out with "git worktree add --force". Will add tests for both.

> I didn't trace all other callers, so there may be other glitches I
> did not notice.

Went through them. fixup, reword, split, squash, drop all call setup_revwalk() before they open an editor, create a commit or update a ref so they refuse early. Will add a test that runs each of them.

> It probably is also worth noting in
> the log message that 'drop' updates the worktree while 'reword',
> 'split', and 'squash' preserve the tip tree and 'fixup' incorporates
> staged changes from the index.
Point taken. Will fix the log message and add that.
Previous: Junio C Hamano
Message 7 of 7 in “history: refuse to rewrite branches used by other worktrees”
  1. history: refuse to rewrite branches used by other worktreesAniket Gupta, Nov 23, 2026
  2. Phillip WoodNov 23, 2026
  3. Aniket GuptaNov 23, 2026
  4. Phillip WoodNov 24, 2026
  5. Aniket GuptaNov 24, 2026
  6. Junio C HamanoNov 23, 2026
  7. Aniket GuptaNov 23, 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.