如何删除“太大"的邮件git历史文件? [英] How to remove "too large" file from git history?

查看:71
本文介绍了如何删除“太大"的邮件git历史文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文件夹中添加了212MB的文件,并提交并尝试将其推送.Git告诉我,文件大小太大,因此我无法推送它.我删除了该文件,但是当我尝试推送代码时仍显示该文件.

I added a 212MB file to my folder and committed it and tried to push it. Git told me that the file size was too big so I can't push it. I deleted the file, but it is still shown when I try to push my code.

我的实际步骤是:

  1. 我做了 git add.

然后 git commit -m"New CSS"

然后 git push原点开发

然后花了很长时间运行以上命令.最后以"path/to/file/file.mp4为212MB,太大.无法推送"结束.

Then it took a long time to run the above command. It ended with saying "path/to/file/file.mp4 is 212MB which is too big. Failed to push".

然后我手动删除了该文件.

Then I deleted that file manually.

再次尝试推送,同样的问题.

Tried pushing again, same problem.

其他stackoverflow答案告诉我使用 git filter-branch --tree-filter'rm -rf path/to/your/file'HEAD

I was told by other stackoverflow answers to use git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD

我只是想了解这意味着什么.这会影响我的整个存储库还是上述文件?如果我已经手动删除了文件,该怎么办?因此文件路径不存在.

I'm just trying to understand what this means. Will this affect my whole repo or just the above mentioned file? What happens if I manually deleted the file already? So the file path doesn't exist.

例如,由于我尝试推送到开发分支,所以我做了 git push origin development .失败了,因此假设我要删除的文件名为Testing.mp4,应该是以下代码:

For example, since I tried pushing to the development branch, I did git push origin development. This failed, so assuming the file I'm trying to delete is named Testing.mp4, should this be the code:

git filter-branch --tree-filter'rm -rf public/uploads/videos/testing.mp4'HEAD

我是对的吗?同样,这只会删除视频,而没有其他内容吗?

Am I right? Again, this will ONLY delete the video and nothing else?

非常感谢您的帮助

推荐答案

从文件系统删除文件并不一定意味着如果它先前已添加到索引(git add path/to/file)中,则将其从git中删除,但是只需记录一个删除操作即可.

deleting the file from filesystem won't necessary mean removing it from git if it was previously added to the index (git add path/to/file), but just record a delete operation.

根据您先前所做的事情,git可能会尝试按顺序执行各种操作:首先添加文件(由于文件大小而导致失败),然后将其删除.

Depending on what you did previousy, git may be trying to push your various actions in order : add the file first (which fail due to file size) then delete it.

要实际上停止跟踪此文件,您可以尝试将其从索引中删除:git rm --cached path/to/file

To actually stop tracking this file you could try to remove it from index : git rm --cached path/to/file

请记住,以后总是"git rm"一个有问题的文件,而不是简单地将其删除,git rm会删除该文件并同时将其从索引中删除.

Remember later to always "git rm" a problematic file rather than simply deleting it, git rm will delete the file AND remove it from index at the same time.

这里是manojlds的一个很好的解释:"gitrm --cached x"vs"git reset head-x"?

A good expanation from manojlds lies here : "git rm --cached x" vs "git reset head -- x"?

问候

这篇关于如何删除“太大"的邮件git历史文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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