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

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

From
Jeff King <peff@peff.net>
Date
Oct 10, 2016, 15:30 UTC
Message-ID
<20161010153032.v2x773cbs4ifvzec@sigill.intra.peff.net>
In-Reply-To
<CAN40BKqPdPP2+K4FBzgDDfYiGkzk1gYcOeP==_t+pr5w0rj0EQ@mail.gmail.com>
On Mon, Oct 10, 2016 at 02:42:36PM +0100, Seaders Oloinsigh wrote:
Show 12 quoted lines
> 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

OK, so that should rewrite each ref to have only the contents of the "android" directory at the top-level.

Note that filter-branch saves a copy of the old refs in refs/original.
Show 9 quoted lines
> 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.

Here you asked for "--all", which includes refs/original. So you are seeing the original, unwritten commits (and none of your new ones, of course, because they do not have a unity/ directory!).

Try:
  git log --all --source -- unity
to see which ref each commit is coming from.
Or try:
  git log --branches --tags -- unity
to confirm that your branches and tags do not include that path.
Or just:
  git for-each-ref --format='delete %(refname)' refs/original |
  git update-ref --stdin
to get rid of the backup refs entirely.
-Peff
Previous: Seaders OloinsighNext: Seaders Oloinsigh
Message 2 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.