【问题标题】:Unable to push the code to new branch on github [duplicate]无法将代码推送到 github 上的新分支 [重复]
【发布时间】:2021-06-24 02:59:29
【问题描述】:

起初我创建了一个新分支来推送代码,然后它给了我 src.zip 大文件的错误,所以我通过文件夹删除了那个大文件,我再次推送了相同的代码,它仍然显示我已经删除的大文件错误。我也创建了一个新的分支来推送,但它也显示了这个分支上大文件的相同错误。新手请帮忙。

Uploading LFS objects: 100% (304/304), 307 MB | 1.1 MB/s, done
Enumerating objects: 1210, done.
Counting objects: 100% (1210/1210), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (774/774), done.
Writing objects: 100% (788/788), 218.86 MiB | 6.96 MiB/s, done.
Total 788 (delta 257), reused 0 (delta 0)
remote: Resolving deltas: 100% (257/257), completed with 81 local objects.
remote: warning: File src/doctorPhone/RaxaFlutter/.dart_tool/flutter_build/2df7223b49177d7318e9bb97b2996866/app.dill is 54.92 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: f7149ed9934cffbf584a9a95455829192e42d3caf9ecb80f50de60b697395238
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File src.zip is 169.55 MB; this exceeds GitHub's file size limit of 100.00 MB
To https://github.com/usename/repoName.git
 ! [remote rejected]     hipconsent -> hipconsent (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/usename/repoName.git'

【问题讨论】:

  • jurez 的回答正确地建议首先咨询所有者,除非您非常确定不需要相关的特定文件。尝试了解他们建议如何存储该特定大文件。通常,文件大小超过 50 MB 时会引发 git 警告,而文件大小超过 100 MB 时会引发错误。管理员似乎配置了不同的大小限制。

标签: git github git-branch git-bash git-lfs


【解决方案1】:

您之前的提交可能仍包含该文件。请尝试从剩余的提交中删除它。

您可以将tree-filterfilter-branch 一起使用,这将从历史记录中完全删除文件,

git filter-branch --tree-filter 'rm -rf app.dill' HEAD

编辑 1:开始

对于重写历史,Git 现在建议使用名为 git filter-repo 的替代工具,而不是 filter-branch

来自 Git 文档:

请使用其他历史过滤工具,例如git filter-repo

上面的filter-branch 命令可以重写为建议的filter-repo 如下:

git filter-repo --invert-paths --path app.dill

编辑 1:结束

【讨论】:

  • 我已经这样做了,上面写着cannot rewrite branches: You have unstaged changes。这是否意味着该文件已被删除?
  • 在 git 的术语中 unstaged changes 表示您有未保存的更改。 git status 应该可以帮助您找出哪些文件尚未暂存。尝试使用 git add 命令暂存您的更改。
  • 运行此命令后说 git filter-branch --tree-filter 'rm -rf app.dill' HEAD:错误:无法创建文件 src/chw/demoVersion2/Icon?:无效参数可能不签出索引
  • 不确定这个unable to create file 问题。看起来有人确实面对similar issue earlier。不记得自己曾经面对过。我记得过去遇到过的与filter-branch 相关的几个问题是没有提供要删除的文件的完整路径,也没有从根目录运行命令。如果该链接仍然无法帮助您尝试使用您的发现更新您的帖子。
【解决方案2】:

设置您的存储库的人决定不希望在其中存储大于 50 MB 的文件。

这通常是有充分理由的。存储大文件(除了某些非常罕见的情况)是使用 git 的反模式。

与存储库的所有者交谈并讨论您的文件应如何存储以及存储在何处。

如果您不想添加这个大文件,请将其从磁盘中删除,告诉 git 更改 (git add filename) 并修改您的提交 (git commit --amend)。此时,您应该能够将您的提交推送到存储库。

【讨论】:

    猜你喜欢
    • 2012-11-23
    • 1970-01-01
    • 2014-11-27
    • 2021-09-12
    • 2011-09-14
    • 2013-01-15
    • 1970-01-01
    • 2016-12-13
    • 2018-05-01
    相关资源
    最近更新 更多