git核武器解决超大文件修改提交被拒

2018-11-14  本文已影响48人  4VZhang

提交本地修改被拒---被拒原文如下:

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree push -v origin dev:dev 
Pushing to https://git.oschina.net/***/jsb_iOS.git
POST git-receive-pack (chunked)
remote: Powered by Gitee.com        
remote: warning: Large files detected.        
remote: error: File Pods/AMap3DMap-NO-IDFA/MAMapKit.framework/MAMapKit is 137.41 MB; this exceeds file size limit of 100.0 MB        
remote: error: hook declined to update refs/heads/dev        
To https://git.oschina.net/***/jsb_iOS.git
 ! [remote rejected] dev -> dev (hook declined)
error: failed to push some refs to 'https://git.oschina.net/***/jsb_iOS.git'
Completed with errors, see above

被拒原因分析:本地提交的修改中包含超过100M大小的文件,导致git拒绝提交!

根据git官网给出的核武器(filter-branch)来解决此问题!同时借鉴前车之鉴

git filter-branch -f  --prune-empty --tree-filter 'rm -f Pods/AMap3DMap-NO-IDFA' HEAD~40..HEAD
Rewrite bb6be8af9994cca8cceb943cf19d1b065a56319c (38/70) (12 seconds passed, remaining 10 predicted)    rm: Pods/AMap3DMap-NO-IDFA: is a directory
tree filter failed: rm -f Pods/AMap3DMap-NO-IDFA

-f十分重要,因为只能删除文件,而不能删除文件夹; 如果有多个文件需要删除就需要 添加上-f的命令,以免第二次运行这个命令出错!

建议:检出一个新分支,在新分支上做如下操作;达到自己想要的效果后,再回到主分支上修改!

//从指定的commit中删除误操作文件的记录
git filter-branch --tree-filter 'git rm -f --ignore-unmatch {{文件名}}' [commit1..commit2]

//从当前分支的前30次提交开始遍历,删除误操作文件的引用
git filter-branch --tree-filter 'git rm -f {{文件名}}' HEAD~30..HEAD

解决办法:

打开终端,
cd到当前项目目录下,
git filter-branch -f --prune-empty --tree-filter 'rm -f Pods/AMap3DMap-NO-IDFA/MAMapKit.framework/MAMapKit' HEAD~40..HEAD

执行结果如下:


执行结果.jpeg
上一篇 下一篇

猜你喜欢

热点阅读