Git - 删除大文件的提交

时间:2017-04-21 15:59:33

标签: git large-files

我错误地提交了一个大文件(> 100Mb),我真的没有必要包含在我的git历史中。

我删除了文件,同样,我将它从git缓存中删除,然后我再次提交。

尽管如此,当我尝试推送到我的远程分支时,git给了我一个大小错误。

我也尝试了git rebase,但提交仍在那里,我该怎么办?

remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 195471c5940ef60fa1dd2ba5a52a4a6a
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File custom_include/xyz.sql is 964.43 MB; this exceeds GitHub's file size limit of 100.00 MB

2 个答案:

答案 0 :(得分:3)

提交大文件后,删除该文件并提交更改将不会将其从历史记录中删除。

只要您知道文件所在的完整路径,就可以使用以下命令从提交历史记录中删除该文件。

但是,请注意:此命令将从您要删除的文件添加的位置重写您的git历史记录。

git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch [path to file to remove]' --prune-empty --tag-name-filter cat -- --all

我从Ted Naleid的这篇优秀博客文章中了解了如何做到这一点:http://naleid.com/blog/2012/01/17/finding-and-purging-big-files-from-git-history

答案 1 :(得分:1)

如果您使用git还原或删除了文件并已提交,那还不够,因为该文件将成为您尝试推送的分支历史记录的一部分。您可以通过修改它来修改添加它的修订版本(这将创建一个fork),然后在修改后修改原始分支上应用的所有更改。

相关问题