將代碼傳到Bitbucket上時,發現Bitbucket有1G空間限制。正好有一個以前項目是用Ant打包的,依賴的jar不少,一查果真超過1G限制,須要將項目的jar分拆成兩個單獨的項目。操做以下。html
假設要將myproject項目中的子目錄sub3拆成單獨項目java
myproject/ .git/ sub1/ sub2/ sub3/ sub3_s1/ sub3_s2/
myproject/ .git/ sub1/ sub2/ sub3/ .git/ sub3_s1/ sub3_s2/
1.查看項目空間大小git
git count-objects -vHgithub
--------------bash
count: 0
size: 0 bytes
in-pack: 325742
packs: 1
size-pack: 377.18 MiB
prune-packable: 0
garbage: 0
size-garbage: 0 bytescode
2.分拆子目錄(sub3)爲新項目orm
git clone /myproject /sub3
git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter sub3 -- --all
git reset --hard git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d git reflog expire --expire=now --all git gc --aggressive --prune=now
3.刪除子目錄並回收空間htm
git filter-branch --tree-filter 'rm -rf sub3' --prune-empty HEAD git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d echo sub3/ >> .gitignore git add .gitignore git commit -m 'Removing sub3 from git history' # Perform a garbage collection to remove commits with no refs git gc --prune=all --aggressive git push origin master --force
4.回收額外空間ip
java -jar bfg.jar --strip-blobs-bigger-than 10M
參考:rem
http://stackoverflow.com/questions/359424/detach-move-subdirectory-into-separate-git-repository
https://help.github.com/articles/splitting-a-subfolder-out-into-a-new-repository/
http://stackoverflow.com/questions/10067848/remove-folder-and-its-contents-from-git-githubs-history
https://confluence.atlassian.com/bitbucket/reduce-repository-size-321848262.html