After successfully converting an SVN repository to Git, I now have a very large Git repository that I want to break down into multiple smaller repositories and maintain history.
So, can someone help with breaking up a repo that might look like this:
MyHugeRepo/ .git/ DIR_A/ DIR_B/ DIR_1/ DIR_2/
Into two repositories that look like this:
MyABRepo/ .git DIR_A/ DIR_B/ My12Repo/ .git DIR_1/ DIR_2/
I've tried following directions in this previous question but it doesn't really fit when trying to put multiple directories into a separate repo (Detach (move) subdirectory into separate Git repository).
remove the file from your project's current file-tree. remove the file from repository history — rewriting Git history, deleting the file from all commits containing it. remove all reflog history that refers to the old commit history. repack the repository, garbage-collecting the now-unused data using git gc.
This will setup MyABRepo; you can do My12Repo similarly of course.
git clone MyHugeRepo/ MyABRepo.tmp/ cd MyABRepo.tmp git filter-branch --prune-empty --index-filter 'git rm --cached --ignore-unmatch DIR_1/* DIR_2/*' HEAD
A reference to .git/refs/original/refs/heads/master remains. You can remove that up with:
cd .. git clone MyABRepo.tmp MyABRepo
If all went well you can then remove MyABRepo.tmp.
If for some reason you get an error regarding .git-rewrite, you can try this:
git clone MyHugeRepo/ MyABRepo.tmp/ cd MyABRepo.tmp git filter-branch -d /tmp/git-rewrite.tmp --prune-empty --index-filter 'git rm --cached --ignore-unmatch DIR_1/* DIR_2/*' HEAD cd .. git clone MyABRepo.tmp MyABRepo
This will create and use /tmp/git-rewrite.tmp as a temporary directory, instead of .git-rewrite
. Naturally, you can substitute any path you wish instead of /tmp/git-rewrite.tmp
, so long as you have write permission, and the directory does not already exist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With