记录一次git提交遇到的问题<commit的文件大于100

2018-01-16  本文已影响198人  Pusswzy

项目集成谷歌的VR SDK后, 提交到github的时候发现报错

The push operation includes a file which exceeds GitHub’s file size restriction of 100MB. Please remove the file from history and try again.

谷歌了一番, 有以下两个解决方案:

方案一

这个方案适用于仅最近的一次提交包含大于100MB的文件, 解决起来也比较简单.
官网解决流程

git rm --cached giant_file
# Stage our giant file for removal, but leave it on disk

git commit --amend -CHEAD
# Amend the previous commit with your change
# Simply making a new commit won't work, as you need
# to remove the file from the unpushed history as well

git push
# Push our rewritten, smaller commit

方案二

这个方案适用于多次的commit已经包含大于100MB的文件, 所以需要对之前的dirty commits进行处理, 这里官网就推荐使用BFG.

# Open Terminal using Spotlight search by pressing <command+space>. Type terminal and hit Enter key.
# Now, Execute
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null

# Install bfg using brew
# 执行这句的时候可能会提示需要Java环境, 按照提示下载Java环境后在执行brew install bfg即可
brew install bfg
# <bfg.jar>指的是你下载bfg.jar的路径
# <.git>指的是你仓库的路径
java -jar <bfg.jar> --no-blob-protection  --strip-blobs-bigger-than 50M <.git>

# example: java -jar /Users/Li/Desktop/bfg/bfg-1.12.16.jar --no-blob-protection  --strip-blobs-bigger-than 50M /Users/Li/Desktop/iOS 

# 找到大文件后再输入
git reflog expire --expire=now --all && git gc --prune=now --aggressive

#then
git push origin master

succees!
上一篇下一篇

猜你喜欢

热点阅读