Split large Git repository into many smaller ones

前端 未结 5 2104
故里飘歌
故里飘歌 2020-11-27 10:12

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 hist

5条回答
  •  误落风尘
    2020-11-27 10:24

    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.

提交回复
热议问题