删除大文件git commit

时间:2014-05-13 08:41:59

标签: git github

我提交了几个大文件,我收到了这个错误

gabbo@gabbo-SATELLITE-L750:/media/Data/Condiviso/TUe/Smartscope_study/smartscope_code$ git add -A
gabbo@gabbo-SATELLITE-L750:/media/Data/Condiviso/TUe/Smartscope_study/smartscope_code$ git commit -m "test"
# On branch master
nothing to commit (working directory clean)
gabbo@gabbo-SATELLITE-L750:/media/Data/Condiviso/TUe/Smartscope_study/smartscope_code$ git push origin master
WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-iLiKTe/pkcs11: No such file or directory
Username for 'https://github.com': gabboshow
Password for 'https://gabboshow@github.com': 
remote: warning: File DATA/segmentation/Feat_2.mat is 94.46 MB; this is larger than GitHub's recommended maximum file size of 50 MB
remote: warning: File DATA/segmentation/Feat_3.mat is 61.77 MB; this is larger than GitHub's recommended maximum file size of 50 MB
remote: warning: File DATA/segmentation/Feat_4.mat is 80.35 MB; this is larger than GitHub's recommended maximum file size of 50 MB
remote: warning: File DATA/segmentation/Feat_5.mat is 85.85 MB; this is larger than GitHub's recommended maximum file size of 50 MB
remote: warning: File DATA/segmentation/Feat_6.mat is 78.94 MB; this is larger than GitHub's recommended maximum file size of 50 MB
remote: warning: File DATA/segmentation/Feat_7.mat is 66.61 MB; this is larger than GitHub's recommended maximum file size of 50 MB
remote: error: GH001: Large files detected.
remote: error: Trace: 66ef415089784516b0d76ac2e639a7ac
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File DATA/segmentation/Feat_1.mat is 123.29 MB; this exceeds GitHub's file size limit of 100 MB
To https://github.com/gabboshow/smartscope_code.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/gabboshow/smartscope_code.git'
gabbo@gabbo-SATELLITE-L750:/media/Data/Condiviso/TUe/Smartscope_study/smartscope_code$ 
之后我搞砸了其他人

git add -A
git commit -m "xxx" 
git push origin master

我确定了导致问​​题的文件。它们列在我的git存储库中名为/large_files.txt的文件中。

129281677 DATA/segmentation/Feat_1.mat
99053081 DATA/segmentation/Feat_2.mat
90017465 DATA/segmentation/Feat_5.mat
84251508 DATA/segmentation/Feat_4.mat
82775151 DATA/segmentation/Feat_6.mat
69845263 DATA/segmentation/Feat_7.mat
64768848 DATA/segmentation/Feat_3.mat

如何继续删除错误的提交并推送我的存储库的干净版本?

1 个答案:

答案 0 :(得分:1)

  

“remote:error:File DATA / segmentation / Feat_1.mat是123.29 MB;这超出了GitHub的文件大小限制100 MB”

您的文件DATA/segmentation/Feat_1.mat超过GITHub的maximum file size 100MB,因此被撤销。从你的问题中可以看出,你没有“错误”的提交。你刚刚推向GitHub失败了。

您可以删除至少这个太大的文件并提交更改。之后,您将能够再次推送到GitHub。

如果您必须对这些大文件进行版本控制,我建议您阅读Working with large files上的帮助文章。

如果您想将这些文件保存在项目文件夹中,我建议您从现在开始忽略它们:

忽略已跟踪的文件

将“DATA / segmentation / * .mat”添加到您的.gitignore(关于该主题还有一个很好的help-resource on GitHub)。

之后,使用以下命令从存储库中删除这些跟踪的文件:

git rm --cached DATA/segmentation/*.mat

将文件解开并让它们现在为git所知。