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

Re: git filter-branch --subdirectory-filter, still a mistery

From
JWJan Wielemaker <j.wielemaker@uva.nl>
Date
Aug 7, 2008, 07:13 UTC
Message-ID
<200808070913.55212.J.Wielemaker@uva.nl>
In-Reply-To
<200808061539.50268.J.Wielemaker@uva.nl>
On Wednesday 06 August 2008 15:39:50 you wrote:
Show 35 quoted lines
> Hi,
>
> I've been puzzling most of today to do something that must be simple.
> I've got a big repo which contains a project with several nicely related
> subprojects in directories. Only now, we want to share some of these
> subprojects with another project. I.e. they must start to live there own
> life. Of course, I would like to keep the history. So, I did (git
> --version: 1.5.6.GIT):
>
>       % git clone /home/git/pl.git
>       % cd pl
>       % git filter-branch --subdirectory-filter packages/chr HEAD
>
> This indeed creates a nice directory holding only the contents of
> packages/chr.  But, starting qgit I see that all commits, also those
> that had absolutely nothing to do with this dir are still there.  Also,
> all tags are still there with exactly the same SHA1 as the original.
> I'd expect the tags to be rewritten such that their SHA1 refers to the
> state of this single directory and its contents!?  Of course, these
> tags give me access to everything, so the repository doesn't shrink
> much too.
>
> I must be missing something important ...  I found similar complaints,
> but few decent answers and the few answer I did find appeared outdated.
> The one at http://use.perl.org/~rjbs/journal/34411 comes closest, although
> the reset --hard is no longer needed and the copying and gc-ing doesn't
> help much anymore.
>
> Should I write a tree-filter that removes all but the directory I want
> to keep?  I.e. something like this?  Feels like and overkill and I fear
> I'll have a lot of empty commits left.
>
>       'mv packages/chr .. && rm -r * && mv ../chr/* . && rmdir ../chr'
>
> I'll be grateful for a clue!
Weirdness goes on.  I tried this:
    git filter-branch --tree-filter '/home/jan/nobackup/tmp2/keep 
packages/chr'
where `keep' is a shell-script:

---------------------------------------------------------------- tmp=/home/jan/nobackup/tmp2 dir="$1"

if [ -d "$dir" ]; then
  b=`basename $dir`
  mv "$dir" $tmp/$b
  rm -rf *
  mv $tmp/$b/* .
  mv $tmp/$b/.??* .
  rmdir $tmp/$b
else
  rm -rf *
fi
----------------------------------------------------------------

This kind of works. I.e. I end up (after 3 hours) with a tree that only contains files from packages/chr. Using qgit it no longer shows the other files in the `tree' view. Only, it has *all* commits of the original project, most of which of course do not change this directory, but now at least their diff is empty. I'd assume there is a command to remove these (which?)

Space wise this isn't ok. The original project GIT is 140M, after this action and a git gc, it is 63M: *much* too big.

Whats more weird: all tags still have the same sha1. I copied using git clone --no-hardlinks pl chr, deleted all refs/tags from packed-refs and gave a "git gc --prune", to end up with 1.1 GIGABYTE repository!?

I'm starting to feel a bit stupid that I can't get this done ...
        Clues?  --- Jan
Previous: Jan WielemakerNext: Thomas Rast
Message 2 of 35 in “git filter-branch --subdirectory-filter, still a mistery”
  1. Jan WielemakerAug 6, 2008
  2. Jan WielemakerAug 7, 2008
  3. Thomas RastAug 7, 2008
  4. Jan WielemakerAug 7, 2008
  5. Thomas RastAug 7, 2008
  6. filter-branch: be more helpful when an annotated tag changesThomas Rast, Aug 7, 2008
  7. filter-branch: add option --delete-unchangedThomas Rast, Aug 8, 2008
  8. Johannes SchindelinAug 9, 2008
  9. Jan WielemakerAug 11, 2008
  10. Felipe ContrerasSep 14, 2008
  11. [RFH] filter-branch: ancestor detection weirdnessThomas Rast, Aug 7, 2008
  12. Johannes SchindelinAug 8, 2008
  13. Thomas RastAug 8, 2008
  14. filter-branch: fix ancestor discovery for --subdirectory-filterThomas Rast, Aug 8, 2008
  15. Johannes SchindelinAug 8, 2008
  16. Thomas RastAug 8, 2008
  17. filter-branch: fix ref rewriting with --subdirectory-filterThomas Rast, Aug 8, 2008
  18. Johannes SchindelinAug 9, 2008
  19. Junio C HamanoAug 9, 2008
  20. Thomas RastAug 9, 2008
  21. Thomas RastAug 9, 2008
  22. filter-branch: use --simplify-mergesThomas Rast, Aug 10, 2008
  23. Junio C HamanoAug 12, 2008
  24. Junio C HamanoAug 12, 2008
  25. Thomas RastAug 12, 2008
  26. Junio C HamanoAug 12, 2008
  27. Petr BaudisAug 12, 2008
  28. Junio C HamanoAug 12, 2008
  29. Thomas RastAug 9, 2008
  30. Junio C HamanoAug 12, 2008
  31. Thomas RastAug 12, 2008
  32. Jan WielemakerAug 8, 2008
  33. Jan WielemakerAug 8, 2008
  34. Documentation: filter-branch: document how to filter all refsThomas Rast, Aug 7, 2008
  35. Documentation: filter-branch: document how to filter all refsThomas Rast, Aug 7, 2008

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.