Hacker News new | ask | show | jobs
by _fbpt 2395 days ago
And after I just spent several hours of headaches rebasing and wrangling git subtree and attempting to git rebase -i branch -s subtree --rebase-merges --allow-unrelated-histories (which doesn't work)...

Request: Is it possible to import only one subdirectory of another Git repository as a subtree (excluding unit tests and build scripts and such)?

3 comments

Git subrepo can import a subdirectory. To oversimplify, it's a wrapper for git subtree that keeps metadata information in both your filesystem and your history so that things stay sane.

https://github.com/ingydotnet/git-subrepo

Does subrepo break when you rebase both a commit and its parent? I recall doing something like that in the past, and subrepo stopped working.
Version 0.4.0 of subrepo has been rock solid for us and has handled everything that's been thrown at it; prior versions wouldn't handle odd situations well. Whether our "odd situations" line up with yours is a different question...

Edit: to be clear; even before 0.4.0 git subrepo handled strange situations better than git subtree did mostly because git subtree requires so much more manual work that's easy to get wrong.

The 'git-subtree' tool (by the same author as this tool) can import subdirectories.
More precisely, git-subtree can extract subdirectories into their own repo, and merge repos into subdirectories.

What someone might want to try is extracting a subdirectory using git-subtree, and then importing it elsewhere using git-subtrac.

Use git-filter-branch with --subdirectory-filter to create a new repo (with history preserved) followed by git-subtree.