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

git filter-branch --subdirectory-filter not working as expected, history of other folders is preserved

From
SOSeaders Oloinsigh <seaders69@gmail.com>
Date
Oct 10, 2016, 13:42 UTC
Message-ID
<CAN40BKqPdPP2+K4FBzgDDfYiGkzk1gYcOeP==_t+pr5w0rj0EQ@mail.gmail.com>
From
https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History
Now your new project root is what was in the trunk subdirectory each time.
> Git will also automatically remove commits that did not affect the
> subdirectory.
>
We have a git repository that looks like

sdk/ android/ ios/ unity/ windows/

Which we'd like to split into 4 repositories, 1 for each platform. To start this process (for splitting android out), I ran,

git filter-branch -f --prune-empty --subdirectory-filter android -- --all

Which rewrote a ton of history and commits, and looked like it worked, but on closer inspection had left a ton of history behind.

If I run
git log --all -- unity/

It returns a list of commits that happened in the unity/ subfolder of the original root.

commit c4ea2797...
Show 5 quoted lines
> Author: tom... <tom@...ve.com>
> Date:   Thu Feb 25 14:20:59 2016 +0000
>
>     kick off build
>
> ...
>

Which only contains an edit to a file with path "unity/tom" relative to the root *before* the filter-branch, doesn't exist any more, and from my understanding of the docs, shouldn't have been taken across.

It's also not an isolated instance, if I run the same checks against "ios/", "windows/", any file that existed in a folder other than "android" to the old root, that history is also preserved.

I've just about resorted to running multiple other, explicit filters to remove all references to those other folders, but it seems like this would be redoing the job that I understood git filter-branch should have been doing.

Any help in this regard is greatly appreciated.
seaders.
Next: Jeff King
Message 1 of 5 in “git filter-branch --subdirectory-filter not working as expected, history of other folders is preserved”
  1. Seaders OloinsighOct 10, 2016
  2. Jeff KingOct 10, 2016
  3. Seaders OloinsighOct 10, 2016
  4. Jeff KingOct 10, 2016
  5. Seaders OloinsighOct 11, 2016

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.