当我尝试推送到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 git@github.com:myUsername/myRepo.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:myUsername/myRepo.git'
Run Code Online (Sandbox Code Playgroud)
我猜我需要从提交中删除大文件,但我该怎么做?
小智 19
git reset --soft HEAD~1
然后从提交中排除该文件。
注意:使用 HEAD~N 返回到之前的 N 次提交。
使用此功能,返回提交,如果可以看到大文件,则从提交中删除它,然后重新提交并推送。
这应该可以解决问题
小智 13
要改进上述答复之一,您需要
git filter-branch -f --tree-filter 'rm -f /path/to/file' HEAD --all
Run Code Online (Sandbox Code Playgroud)
为了甚至从历史记录中删除您的文件。您需要-f强制重写任何备份并--all从所有分支中删除文件。更多信息在这里:Git docs
将大文件错误从 git 缓存中删除并不会消失,因为它仍然潜伏在提交历史记录中。
小智 11
我已经删除了该文件,认为这会有所帮助。在分支上运行这个命令对我有用。
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch path/to/file'
Run Code Online (Sandbox Code Playgroud)
要删除大文件,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
Run Code Online (Sandbox Code Playgroud)
或者,如果您想了解有关如何在GitHub上处理大文件的更多常规信息.
下次加入/log你的.gitignore
截至 2022 年 10 月,git 指示用户使用“git filter-repo”,因为:
WARNING: git-filter-branch has a glut of gotchas generating mangled history
rewrites. Hit Ctrl-C before proceeding to abort, then use an
alternative filtering tool such as 'git filter-repo'
(https://github.com/newren/git-filter-repo/) instead. See the
filter-branch manual page for more details; to squelch this warning,
set FILTER_BRANCH_SQUELCH_WARNING=1.
Run Code Online (Sandbox Code Playgroud)
如果(由于某种原因)git-filter-repo( https://github.com/newren/git-filter-repo/ )的文档不完全清楚,那么以下内容肯定会让你走上正轨(它对我来说是这样) ,因为我显然有点迟钝):
https://superuser.com/a/1589985/1054410
git-filter-repo 文档中的以下示例展示了如何在以下内容之间进行转换:
git filter-branch -f --tree-filter 'rm -f /path/to/file' HEAD --all
Run Code Online (Sandbox Code Playgroud)
到
git filter-repo --invert-paths --path /path/to/file
Run Code Online (Sandbox Code Playgroud)
最后,您可能需要在语句末尾添加“--force”,因为 git filter-repo 需要“新鲜克隆”。
Aborting: Refusing to destructively overwrite repo history since
this does not look like a fresh clone.
(expected freshly packed repo)
Please operate on a fresh clone instead. If you want to proceed
anyway, use --force.
Run Code Online (Sandbox Code Playgroud)
我最近遇到了同样的问题,您实际上可以只过滤特定文件的分支并将其删除-
git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD
Run Code Online (Sandbox Code Playgroud)
您可以在提交之前恢复 git add 。
检查这个问题:How to undo 'git add' before commit? 它应该有效。并且不要将大文件发送到 git,这是不值得的;)
另外,通过在日志路径上添加 gitignore 来排除日志。
| 归档时间: |
|
| 查看次数: |
11748 次 |
| 最近记录: |