Git-删除大文件的提交 [英] Git - remove commit of large file

查看:395
本文介绍了Git-删除大文件的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我错误地提交了一个我实际上不必包含在git历史记录中的大文件(> 100Mb).

I erroneously committed a big file (>100Mb) that I really didn't have to include in my git history.

我也删除了该文件,也从git缓存中删除了该文件,然后再次提交.

I removed the file, also, I removed it from git cache, then I committed again.

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

Despite this, when I try to push to my remote branch, git gives me a size error.

我也尝试了git rebase,但是提交仍然存在,我该怎么办?

I also tried a git rebase, but the commit is still there, what shall I do?

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

推荐答案

一旦提交了大文件,将其删除并提交更改将不会从历史记录中将其删除.

Once you have committed the large file, deleting it and committing that change will not remove it from the history.

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

As long as you know the full path where the file was located you can use the command below to remove the file from the commit history.

但是,请注意:此命令将从添加删除文件的那一刻起重新编写您的git历史记录.

However, please be aware: this command will re-write your git history from the point at which the file you are removing was added.

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的这篇出色的博客文章中学到了如何做到这一点:

I learnt how to do this from this excellent blog post by Ted Naleid: http://naleid.com/blog/2012/01/17/finding-and-purging-big-files-from-git-history

这篇关于Git-删除大文件的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆