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

Re: [Bug] Git subtree regression

From
CSColin Stagner <ask+git@howdoi.land>
Date
Jan 5, 2026, 03:36 UTC
Message-ID
<4a9c1a5f-336a-472c-af1d-7011fad776a6@howdoi.land>
In-Reply-To
<20260104142733.2334796-1-george@mail.dietrich.pub>
On 1/4/26 08:27, george@mail.dietrich.pub wrote:
> It does seem one component was added differently, as a non-merge commit, which seems break things.
Show 19 quoted lines
> ```
> # Create a LINEAR squash commit for subB (simulating cherry-pick of just the squash commit)
> # This is the key pattern that triggers the bug - a squash commit as a regular linear commit
> (
>      cd monorepo
>      mkdir -p subB
>      git -C ../subB archive HEAD | tar -x -C subB
>      git add subB
>      # Create a squash-style commit with subtree trailers but as a LINEAR commit
>      # Trailers must be in the last paragraph, separated by blank line
>      subB_short=$(git -C ../subB rev-parse --short HEAD)
>      subB_full=$(git -C ../subB rev-parse HEAD)
>      git commit -F - <<EOF
> Squashed 'subB/' content from commit $subB_short
> git-subtree-dir: subB
> git-subtree-split: $subB_full
> EOF
> )
> ```
Yes, this is very likely to cause breakage.
Normally,
     git subtree merge -P subA --squash
makes two commits, in this order:
1. Squashed 'subA/' content from commit f00...
2. Merge commit (1) as 'subA'

Commit 1 updates the subtree but does *not* rewrite paths. If you `git show` one, you will see that it has files like

     subA1
     subA2
and *not* subA/subA1.

The path rewrite actually takes place in Commit 2 (the merge), via the `-Xsubtree` merge strategy option.

`should_ignore_subtree_split_commit` tries to search for commits like (1), which all have the `git-subtree-*` trailer. Normally, these commits either have:

* no parents, if they result from a new `git subtree add --squash`; OR
* only parents which are also "Squashed 'subA/' content," if
   they result from a follow-up `git subtree merge --squash`

We can safely ignore these commits—and all of their parents—during a `subtree split` if they belong to a different subtree.

Of course, that heuristic doesn't work if the commit has been rebased onto other unrelated history—which is what happened in your repo.

I suspect the best way out may be to remove the `should_ignore_subtree_split_commit` heuristic entirely. It is mostly useful for repos that use `split --rejoin` a lot, and the check itself is slow. WDYT?

> How the first two commits show up as verified, unlike the other times when I normally do `git subtree add --squash` and push directly to main, they show up as unverified.

git v2.51.0 also adds --gpg-sign compatibility to subtree. Perhaps this is what you are seeing?

> It seems you also need to add `clock` as a remote and fetch it:
Ah, thanks.

Personally, I'm a big advocate for the monorepo layout. In my experience, it makes almost every task easier and faster.

Colin
Previous: george@mail.dietrich.pubNext: george@mail.dietrich.pub
Message 5 of 11 in “[Bug] Git subtree regression”
  1. dev@dietrich.pubDec 26, 2025
  2. george@mail.dietrich.pubDec 30, 2025
  3. Colin StagnerJan 4, 2026
  4. george@mail.dietrich.pubJan 4, 2026
  5. Colin StagnerJan 5, 2026
  6. george@mail.dietrich.pubJan 6, 2026
  7. Colin StagnerJan 10, 2026
  8. george@mail.dietrich.pubJan 10, 2026
  9. Colin StagnerFeb 15, 2026
  10. D. Ben KnobleFeb 16, 2026
  11. george@mail.dietrich.pubFeb 18, 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.