赞
踩
在频繁增删改、commit之后,.git文件会出现过大的情况
这个时候需要彻底清理以前的历史版本(也就是说只保留当前版本,不可能再回滚了)
中心思想就是创建一个新工程把现有代码拷贝过去
git init
创建新仓库git remote add origin url
添加远程仓库地址git add .
git commit -m "message"
git push -f origin master
注意:一定是强制更新远程仓库的,因为原先的git记录都将不再,直接push是有冲突的
方法是首先建立一个分支,然后将master版本给删除,再将当前分支重命名为master,再强制push到远程仓库即可
git checkout --orphan latest_branch
git add -A
git commit -m "commit message"
git branch -D master
git branch -m master
git push -f origin master
就此完成。
这里是修改.git文件夹中的内容
#!/bin/bash COMM=`git verify-pack -v .git/objects/pack/pack-*.idx | sort -k 3 -g | tail -10 >1.txt` for value in `cat 1.txt |awk '{print $1}'` do git rev-list --objects --all | grep "${value}" >2.txt a=`cat 2.txt |awk '{print $2}'` git log --pretty=oneline --branches -- ${a} git filter-branch --index-filter "git rm --cached --ignore-unmatch ${a}" -- --all git push --force rm -Rf .git/refs/original rm -Rf .git/logs/ git gc git prune done
这个代码没有测试,不知道能不能成功,推荐方法1或者2
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。