git版本库中删除文件的历史记录

有时候不小心把一些大文件commit到了本地版本库,但往网络版本库同步时,因为文件过大被拒绝。如果在上传前,本地有多次提交,此时再在当前版本里删除这些大文件还不够,还需要把历史记录全删掉。效果要跟从来没提交过这些文件一样。

# 删除匹配文件
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *.zip' 

# 回收空间
rm -rf .git/refs/original/ 
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
du .git -lsh 

# 同步到网络
git push origin master --force
Copyright © zhiqiang.org 2016 all right reserved,powered by Gitbook该文件修订时间: 2016-08-03 01:06:06

results matching ""

    No results matching ""