3 回答

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超8個(gè)贊
我發(fā)現(xiàn)--tree-filter其他答案中使用的選項(xiàng)可能非常慢,尤其是在具有大量提交的大型存儲(chǔ)庫(kù)中。
這是我使用--index-filter選項(xiàng)可以從git歷史記錄中完全刪除目錄的方法,該方法運(yùn)行起來(lái)要快得多:
# Make a fresh clone of YOUR_REPO
git clone YOUR_REPO
cd YOUR_REPO
# Create tracking branches of all branches
for remote in `git branch -r | grep -v /HEAD`; do git checkout --track $remote ; done
# Remove DIRECTORY_NAME from all commits, then remove the refs to the old commits
# (repeat these two commands for as many directories that you want to remove)
git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch DIRECTORY_NAME/' --prune-empty --tag-name-filter cat -- --all
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
# Ensure all old refs are fully removed
rm -Rf .git/logs .git/refs/original
# Perform a garbage collection to remove commits with no refs
git gc --prune=all --aggressive
# Force push all branches to overwrite their history
# (use with caution!)
git push origin --all --force
git push origin --tags --force
您可以使用以下命令檢查存儲(chǔ)庫(kù)的大小gc:
git count-objects -vH
- 3 回答
- 0 關(guān)注
- 1084 瀏覽
添加回答
舉報(bào)