git Git错误,需要删除大文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33360043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git error, need to remove large file
提问by Daniel
I am getting this error when I try to push to git and I have no idea how to fix it.
当我尝试推送到 git 时出现此错误,但我不知道如何修复它。
Counting objects: 1239, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1062/1062), done.
Writing objects: 100% (1239/1239), 26.49 MiB | 679.00 KiB/s, done.
Total 1239 (delta 128), reused 0 (delta 0)
remote: warning: File log/development.log is 98.59 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: efd2d13efa4a231e3216dad097ec25d6
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File log/development.log is 108.86 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File log/development.log is 108.74 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File log/development.log is 108.56 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File log/development.log is 106.58 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File log/development.log is 103.70 MB; this exceeds GitHub's file size limit of 100.00 MB
To [email protected]:myUsername/myRepo.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]:myUsername/myRepo.git'
I'm guessing I need to remove the large file from the commit, but how do I do that?
我猜我需要从提交中删除大文件,但我该怎么做?
回答by Daniel Andrei Minc?
To remove large files, GitHub suggests:
要删除大文件,GitHub建议:
$ 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
Or if you want more general informationon how to work with large files on GitHub.
或者,如果您想了解有关如何在 GitHub 上处理大文件的更多一般信息。
And next time add /log
in your .gitignore
下次加入/log
你的.gitignore
回答by Ritesh Chandnani
I faced the same issue recently, you can actually just filter the branch for specific file and remove it -
我最近遇到了同样的问题,您实际上可以过滤特定文件的分支并将其删除-
git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD
回答by user30850
To improve upon one of the reply above, you need
要改进上述答复之一,您需要
git filter-branch -f --tree-filter 'rm -f /path/to/file' HEAD --all
in order to remove your file even from the history. You need -f
to force rewriting any backup and --all
to remove file from all branches. More information here: Git docs
为了甚至从历史记录中删除您的文件。您需要-f
强制重写任何备份并--all
从所有分支中删除文件。更多信息在这里:Git docs
Your large file error won't go away by removing it from the git cache because it is still lurking in the commit history.
将大文件错误从 git 缓存中删除并不会消失,因为它仍然潜伏在提交历史中。
回答by Timbus Calin
Adding to the previous answers:
添加到以前的答案:
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch path_to_the_file/your_big_file
'
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch path_to_the_file/your_big_file
'
Additionally, when I tried to pull I got "Refusing to merge unrelated histories".
此外,当我尝试拉取时,我得到了“拒绝合并不相关的历史记录”。
Solution was to use : git pull origin branch_name --allow-unrelated-histories
.
解决方案是使用 : git pull origin branch_name --allow-unrelated-histories
。
Then solve your possible conflicts, and push this time without the big_file.
然后解决你可能的冲突,这次推送没有big_file。
回答by guy
Adding to the previous answers:
添加到以前的答案:
We are going to remove the large file from the commit as you said
正如您所说,我们将从提交中删除大文件
Do the push from the terminal just to get the large file path
git push --set-upstream origin Remote_branch_name
, locate the large file path in the errors, something likeRepositoryName/folders.../bigFileName
.Remove the file from all the branches,
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch path_and_big_file'
past the path that we found in section one instead ofpath_and_big_file
.Execute
git pull origin branch_name --allow-unrelated-histories
to not getunrelated histories
errorNow try to push to git, it should work
从终端执行推送只是为了获取大文件路径
git push --set-upstream origin Remote_branch_name
,在错误中找到大文件路径,例如RepositoryName/folders.../bigFileName
.从所有分支中删除文件,
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch path_and_big_file'
越过我们在第一节中找到的路径而不是path_and_big_file
.执行
git pull origin branch_name --allow-unrelated-histories
不unrelated histories
报错现在尝试推送到 git,它应该可以工作
回答by m.aibin
You can revert git add before commit.
您可以在提交之前恢复 git add 。
Check this question: How to undo 'git add' before commit?It should work. And don't send big files to git, it's not worthy ;)
检查这个问题:How to undo 'git add' before commit? 它应该工作。并且不要将大文件发送到 git,这是不值得的;)
Also, exclude your logs, by adding git ignore on your logs path.
此外,通过在日志路径上添加 git ignore 来排除日志。
回答by hgsongra
@Daniel
@丹尼尔
You can ignore that log(s) file from git repo using .gitignore
file.
for that you have to add below line to your .gitignore
file
您可以使用 file.git repo 从 git repo 忽略该日志.gitignore
文件。为此,您必须在.gitignore
文件中添加以下行
/log
and try to commit again.
Hope this details help you to fix your issue.
并尝试再次提交。
希望这些详细信息可以帮助您解决问题。
回答by Sithija Piyuman Thewa Hettige
git reset --soft HEAD~1
git reset --soft HEAD~1
then exclude the file from the commit.
然后从提交中排除该文件。
Note: Use HEAD~N to go back to N number of previous commits.
注意:使用 HEAD~N 返回到 N 次之前的提交。
use this , go back a commit ,remove the large file from the commit if you can see it , then re commit and push.
使用这个,返回一个提交,如果你能看到它,从提交中删除大文件,然后重新提交并推送。
this should solve the problem
这应该可以解决问题