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, 10:14 UTC
Message-ID
<200808071214.25399.J.Wielemaker@uva.nl>
In-Reply-To
<200808070950.23754.trast@student.ethz.ch>
Hi Thomas,
On Thursday 07 August 2008 09:50:03 am Thomas Rast wrote:
Show 21 quoted lines
> Jan Wielemaker wrote:
> [...]
>
> > 	% 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.
>
> The trick is to rewrite all refs, not just HEAD.  I usually proceed as
> follows:
>
>   cp -a repo repo.old  # just to keep a backup
>   cd repo
>   git filter-branch --subdirectory-filter somedir -- --all
>
> The --all tells it to rewrite as many refs as possible.  Note that the
> -- is required.  Also note that refs/original/* will still point to
> the old commits, so they won't "just vanish".  You may want to clone
> the repository or delete them manually once you are sure the
> filter-branch did the right thing.

Thanks. That is moving in the right direction! There are some, possibly related, problems left (using 1.5.6.GIT). According to git fsck, my repo is clean. I got:

  Ref 'refs/tags/V5.6.50' was rewritten
  error: Ref refs/tags/V5.6.50 is at 8678b32f71178019c06aefa40e2d3fb9a2e8ef25 
but
	expected 2e8aef64e2fed088720a19ac2ffa2481e5bc7806
  fatal: Cannot lock the ref 'refs/tags/V5.6.50'.
  Could not rewrite refs/tags/V5.6.50

Now, if I look in .git/packed-refs, I see this (i.e. a second line with a ^) for all refs that cause problems:

274ec8ac671542206ba3567ff5d72b3e54c5603c refs/tags/V5.6.59 ^28920c3c0a184698d9cd15a65cd643367200bbf5 faf203f9d9e350d84b6b38b7746e710b6232fc97 refs/tags/V5.6.58 ^1edb1adedcc47ec15c3242234cc6b7ede94bbfba 48488c871227beabcb3ba167b737d6e33ced65bc refs/tags/V5.6.57 ^766587b09e3d2f09c87b03ad0d7faf3529c9dcff

After a bit of puzzling I discovered the the SHA1 after the ^ refers to the actual commit and I changed all these to `lightweight' tags by putting the SHA1 behind ^ before the tag itself. I wrote a little sh/awk script to automate this (attached).

Now it runs to the end. Unfortunagtely the history is completely screwed up :-(:

	* There are a lot of commits that are not related to the dir
	* Commits start long before the directory came into existence,
	Looks like it just shows the whole project at this place.

I think the problem is related to the fact that the directory I want to filter didn't exists at the start of the project. Looking at git-rev-list, I found --remove-empty, so I added that after the --all, but that doesn't appear to help. I must admit I don't really know what I'm doing (though I still think the result I want it well defined and its hard to imagine I'm the only person who wants this).

If someone wants to help: clone git://gollem.science.uva.nl/home/git/pl.git and try to filter the dir packages/chr. You can browse the git at http://gollem.science.uva.nl/git/pl.git

	Thanks --- Jan
Previous: Thomas RastNext: Thomas Rast
Message 4 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.