<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/contrib/subtree/git-subtree.sh, branch main</title>
<subtitle>Fork of git SCM with my patches.</subtitle>
<id>http://git.kilabit.info/git/atom?h=main</id>
<link rel='self' href='http://git.kilabit.info/git/atom?h=main'/>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/'/>
<updated>2026-03-03T19:08:12Z</updated>
<entry>
<title>Merge branch 'cs/subtree-split-fixes'</title>
<updated>2026-03-03T19:08:12Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2026-03-03T19:08:12Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=2f9980cfebad39326546e4db1f614bdaf783f51b'/>
<id>urn:sha1:2f9980cfebad39326546e4db1f614bdaf783f51b</id>
<content type='text'>
An earlier attempt to optimize "git subtree" discarded too much
relevant histories, which has been corrected.

* cs/subtree-split-fixes:
  contrib/subtree: process out-of-prefix subtrees
  contrib/subtree: test history depth
  contrib/subtree: capture additional test-cases
</content>
</entry>
<entry>
<title>contrib/subtree: process out-of-prefix subtrees</title>
<updated>2026-02-20T18:15:31Z</updated>
<author>
<name>Colin Stagner</name>
<email>ask+git@howdoi.land</email>
</author>
<published>2026-02-18T02:31:32Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=1f70684b517f4fcfeb7b998b0b7f3146ee8a8c75'/>
<id>urn:sha1:1f70684b517f4fcfeb7b998b0b7f3146ee8a8c75</id>
<content type='text'>
`should_ignore_subtree_split_commit` detects subtrees which are
outside of the current path --prefix and ignores them. This can
speed up splits of repositories that have many subtrees.

Since its inception [1], every iteration of this logic [2], [3]
incorrectly excludes commits. This alters the split history. The
split history and its commit hashes are API contract, so this is
not permissible.

While a commit from a different subtree may look like it doesn't
contribute anything to a split, sometimes it does. Merge commits
are a particular hot spot. For these, the pruning logic in
`copy_or_skip` performs:

1. a check for "treesame" parents
2. two different common ancestry checks

These checks operate on the **split history**, not the input
history. The split history omits commits that do not affect the
--prefix. This can significantly alter the ancestry of a merge.
In order to determine if `copy_or_skip` will skip a merge, it
is likely necessary to compute all the split history... which
is what `should_ignore_subtree_split_commit` tries to avoid.

To make this logic API-preserving, we could gate it behind a
new CLI argument. The present implementation is actually a
speed penalty in many cases, however, so this is not done here.

Remove the `should_ignore_subtree_split_commit` logic. This
fixes the regression reported in [4].

[1]: 98ba49ccc2 (subtree: fix split processing with multiple subtrees present, 2023-12-01)

[2]: 83f9dad7d6 (contrib/subtree: fix split with squashed subtrees, 2025-09-09)

[3]: 28a7e27cff (contrib/subtree: detect rewritten subtree commits, 2026-01-09)

[4]: &lt;20251230170719.845029-1-george@mail.dietrich.pub&gt;

Reported-by: George &lt;george@mail.dietrich.pub&gt;
Reported-by: Christian Heusel &lt;christian@heusel.eu&gt;
Signed-off-by: Colin Stagner &lt;ask+git@howdoi.land&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>subtree: validate --prefix against commit in split</title>
<updated>2026-02-03T17:26:45Z</updated>
<author>
<name>Pushkar Singh</name>
<email>pushkarkumarsingh1970@gmail.com</email>
</author>
<published>2026-02-03T16:48:16Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=a606fcdceb807b93013542e5e4d5f4c233aa6c83'/>
<id>urn:sha1:a606fcdceb807b93013542e5e4d5f4c233aa6c83</id>
<content type='text'>
git subtree split currently validates --prefix against the working tree.
This breaks when splitting an older commit or when the working tree does
not contain the subtree, even though the commit does.

For example:

  git subtree split --prefix=pkg &lt;commit&gt;

fails if pkg was removed later, even though it exists in &lt;commit&gt;.

Fix this by validating the prefix against the specified commit using
git cat-file instead of the working tree.

Add a test to ensure this behavior does not regress.

Signed-off-by: Pushkar Singh &lt;pushkarkumarsingh1970@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Revert "Merge branch 'cs/rebased-subtree-split'"</title>
<updated>2026-01-26T06:37:35Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2026-01-25T17:43:29Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=ab689ea7f91ab0858e85776f31102203d3ea7b83'/>
<id>urn:sha1:ab689ea7f91ab0858e85776f31102203d3ea7b83</id>
<content type='text'>
This reverts commit 79e3055baba32e2952e6e8994cdcd4fc145ba7f0, reversing
changes made to 9813aace1e52765e01e688672cdcdcbe25336ec7.

Regresison report

    https://lore.kernel.org/git/755578cb-07e0-4b40-aa90-aacf4d45ccaa@heusel.eu/
</content>
</entry>
<entry>
<title>contrib/subtree: detect rewritten subtree commits</title>
<updated>2026-01-10T04:21:43Z</updated>
<author>
<name>Colin Stagner</name>
<email>ask+git@howdoi.land</email>
</author>
<published>2026-01-10T01:18:11Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=28a7e27cff717e5ef91f7445e6a418068608082d'/>
<id>urn:sha1:28a7e27cff717e5ef91f7445e6a418068608082d</id>
<content type='text'>
    git subtree split --prefix P

detects splits that are outside of path prefix `P` and prunes
them from history graph processing. This improves the performance
of repeated `split --rejoin` with many different prefixes.

Both before and after 83f9dad7d6 (contrib/subtree: fix split with
squashed subtrees, 2025-09-09), the pruning logic does not detect
**rebased** or **cherry-picked** git-subtree commits. If `split`
encounters any of these commits, the split output may have
incomplete history.

All commits authored by

    git subtree merge [--squash] --prefix Q

have a first or second parent that has *only* subtree commits
as ancestors. When splitting a completely different path `P/`,
it is safe to ignore:

1. the merged tree
2. the subtree parent
3. *all* of that parent's ancestry, which applies only to
   path `Q/` and not `P/`.

But this relationship no longer holds if the git-subtree commit
is rebased or otherwise reauthored. After a rebase, the former
git-subtree commit will have other unrelated commits as ancestors.
Ignoring these commits may exclude the history of `P/`,
leading to incomplete `subtree split` output.

The pruning logic relies solely on the `git-subtree-*:` trailers
to detect git-subtree commits, which it blindly accepts without
further validation. The split logic also takes its time about
being wrong: `cmd_split()` execs a `git show` for *every* commit
in the split range… twice. This is inefficient in a shell script.

Add a "reality check" to ignore rebased or rewritten commits:

* Rewrites of non-merge commits cannot be detected, so the new
  detector no longer looks for them.

* Merges carry a `git-subtree-mainline:` trailer with the hash of
  the **first parent**. If this hash differs, or if the "merge"
  commit no longer has multiple parents, a rewrite has occurred.

To increase speed, package this logic in a new method,
`find_other_splits()`. Perform the check up-front by iterating
over a single `git log`. Add ignored subtrees to:

1. the `notree` cache, which excludes them from the `split` history

2. a `prune` negative refs list. The negative refs prevent
   recursing into other subtrees. Since there are potentially a
   *lot* of these, cache them on disk and use rev-list's
   `--stdin` mode.

Reported-by: George &lt;george@mail.dietrich.pub&gt;
Signed-off-by: Colin Stagner &lt;ask+git@howdoi.land&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>contrib/subtree: fix split with squashed subtrees</title>
<updated>2025-09-11T16:01:15Z</updated>
<author>
<name>Colin Stagner</name>
<email>ask+git@howdoi.land</email>
</author>
<published>2025-09-10T03:11:24Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=83f9dad7d6fb5988b68f80b25bd87c68693195dd'/>
<id>urn:sha1:83f9dad7d6fb5988b68f80b25bd87c68693195dd</id>
<content type='text'>
98ba49ccc2 (subtree: fix split processing with multiple subtrees
present, 2023-12-01) increases the performance of

    git subtree split --prefix=subA

by ignoring subtree merges which are outside of `subA/`. It also
introduces a regression. Subtree merges that should be retained
are incorrectly ignored if they:

1. are nested under `subA/`; and
2. are merged with `--squash`.

For example, a subtree merged like:

    git subtree merge --squash --prefix=subA/subB "$rev"
    #                 ^^^^^^^^          ^^^^

is erroneously ignored during a split of `subA`. This causes
missing tree files and different commit hashes starting in
git v2.44.0-rc0.

The method:

    should_ignore_subtree_split_commit REV

should test only a single commit REV, but the combination of

    git log -1 --grep=...

actually searches all *parent* commits until a `--grep` match is
discovered.

Rewrite this method to test only one REV at a time. Extract commit
information with a single `git` call as opposed to three. The
`test` conditions for rejecting a commit remain unchanged.

Unit tests now cover nested subtrees.

Signed-off-by: Colin Stagner &lt;ask+git@howdoi.land&gt;
Acked-by: Phillip Wood &lt;phillip.wood@dunelm.org.uk&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>contrib/subtree: add -S/--gpg-sign</title>
<updated>2025-06-04T16:32:17Z</updated>
<author>
<name>Patrik Weiskircher</name>
<email>patrik@pspdfkit.com</email>
</author>
<published>2025-06-04T14:16:37Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=fea50ce4118c38d74d05c3595abe7756cabee4e1'/>
<id>urn:sha1:fea50ce4118c38d74d05c3595abe7756cabee4e1</id>
<content type='text'>
Allows optionally signing the commits that git subtree creates. This can
be necessary when working in a repository that requires gpg signed
commits.

Signed-off-by: Patrik Weiskircher &lt;patrik@pspdfkit.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>contrib/subtree: parse using --stuck-long</title>
<updated>2025-06-04T16:32:17Z</updated>
<author>
<name>Patrik Weiskircher</name>
<email>patrik@pspdfkit.com</email>
</author>
<published>2025-06-04T14:16:36Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=7cd080acf65a96032824f3b5faad506346b69f5c'/>
<id>urn:sha1:7cd080acf65a96032824f3b5faad506346b69f5c</id>
<content type='text'>
Optional parameter handling only works unambiguous with git rev-parse
--parseopt when using the --stuck-long option. To prepare for future commits
which add flags with optional parameters, parse with --stuck-long.

Signed-off-by: Patrik Weiskircher &lt;patrik@pspdfkit.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>contrib: fix typos</title>
<updated>2024-10-10T20:31:12Z</updated>
<author>
<name>Andrew Kreimer</name>
<email>algonell@gmail.com</email>
</author>
<published>2024-10-10T15:11:20Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=f5dedddb753e5366168052cc9cbfec760bbeb3ee'/>
<id>urn:sha1:f5dedddb753e5366168052cc9cbfec760bbeb3ee</id>
<content type='text'>
Fix typos via codespell.

Signed-off-by: Andrew Kreimer &lt;algonell@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>subtree: fix split processing with multiple subtrees present</title>
<updated>2024-01-25T18:56:34Z</updated>
<author>
<name>Zach FettersMoore</name>
<email>zach.fetters@apollographql.com</email>
</author>
<published>2023-12-01T14:54:54Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=98ba49ccc247c3521659aa3d43c970e8978922c5'/>
<id>urn:sha1:98ba49ccc247c3521659aa3d43c970e8978922c5</id>
<content type='text'>
When there are multiple subtrees present in a repository and they are
all using 'git subtree split', the 'split' command can take a
significant (and constantly growing) amount of time to run even when
using the '--rejoin' flag. This is due to the fact that when processing
commits to determine the last known split to start from when looking
for changes, if there has been a split/merge done from another subtree
there will be 2 split commits, one mainline and one subtree, for the
second subtree that are part of the processing. The non-mainline
subtree split commit will cause the processing to always need to search
the entire history of the given subtree as part of its processing even
though those commits are totally irrelevant to the current subtree
split being run.

To see this in practice you can use the open source GitHub repo
'apollo-ios-dev' and do the following in order:

-Make a changes to a file in 'apollo-ios' and 'apollo-ios-codegen'
 directories
-Create a commit containing these changes
-Do a split on apollo-ios-codegen
   - Do a fetch on the subtree repo
      - git fetch git@github.com:apollographql/apollo-ios-codegen.git
   - git subtree split --prefix=apollo-ios-codegen --squash --rejoin
   - Depending on the current state of the 'apollo-ios-dev' repo
     you may see the issue at this point if the last split was on
     apollo-ios
-Do a split on apollo-ios
   - Do a fetch on the subtree repo
      - git fetch git@github.com:apollographql/apollo-ios.git
   - git subtree split --prefix=apollo-ios --squash --rejoin
-Make changes to a file in apollo-ios-codegen
-Create a commit containing the change(s)
-Do a split on apollo-ios-codegen
   - git subtree split --prefix=apollo-ios-codegen --squash --rejoin
-To see that the patch fixes the issue you can use the custom subtree
 script in the repo so following the same steps as above, except
 instead of using 'git subtree ...' for the commands use
 'git-subtree.sh ...' for the commands

You will see that the final split is looking for the last split
on apollo-ios-codegen to use as it's starting point to process
commits. Since there is a split commit from apollo-ios in between the
2 splits run on apollo-ios-codegen, the processing ends up traversing
the entire history of apollo-ios which increases the time it takes to
do a split based on how long of a history apollo-ios has, while none
of these commits are relevant to the split being done on
apollo-ios-codegen.

So this commit makes a change to the processing of commits for the
split command in order to ignore non-mainline commits from other
subtrees such as apollo-ios in the above breakdown by adding a new
function 'should_ignore_subtree_commit' which is called during
'process_split_commit'. This allows the split/rejoin processing to
still function as expected but removes all of the unnecessary
processing that takes place currently which greatly inflates the
processing time. In the above example, previously the final split
would take ~10-12 minutes, while after this fix it takes seconds.

Added a test to validate that the proposed fix
solves the issue.

The test accomplishes this by checking the output
of the split command to ensure the output from
the progress of 'process_split_commit' function
that represents the 'extracount' of commits
processed remains at 0, meaning none of the commits
from the second subtree were processed.

This was tested against the original functionality
to show the test failed, and then with this fix
to show the test passes.

This illustrated that when using multiple subtrees,
A and B, when doing a split on subtree B, the
processing does not traverse the entire history
of subtree A which is unnecessary and would cause
the 'extracount' of processed commits to climb
based on the number of commits in the history of
subtree A.

Signed-off-by: Zach FettersMoore &lt;zach.fetters@apollographql.com&gt;
Reviewed-by: Christian Couder &lt;christian.couder@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
