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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…