当使用git push到远程仓库时出现错误:“文件java_pid66619.hprof大小为661.61 MB,超过了GitHub的文件大小限制100.00 MB”。

5

我正在使用Intellij IDE开发一个Java AWT应用程序。在我提交了代码之后,将其推送到仓库:

me@mine-laptop myproject (master)$ git push origin master
Enumerating objects: 77, done.
Counting objects: 100% (77/77), done.
Delta compression using up to 4 threads
Compressing objects: 100% (58/58), done.
Writing objects: 100% (76/76), 114.51 MiB | 957.00 KiB/s, done.
Total 76 (delta 5), reused 1 (delta 0)
remote: Resolving deltas: 100% (5/5), done.
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 41b3b658daba463dbc5ad37bce34f785
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File java_pid66619.hprof is 661.61 MB; this exceeds GitHub's file size limit of 100.00 MB
To github.com:myname/myproject.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:myname/myproject.git'

报错说我有一个大文件java_pid66619.hprof,导致git push失败。

然后我将这个文件添加到我的.gitignore中并再次push,但仍然出现相同的错误。

接着我运行ls -la命令,但是我没有看到那个大文件java_pid66619.hprof。我知道这个大文件是堆转储。

我的问题:

  1. 为什么我用ls -al看不到那个文件,但是git在push时还是会抱怨它?
  2. 为什么我已经在git中将它忽略了,但仍然会被抱怨?
  3. 如何解决这个问题?

1
  1. 因为它在之前的提交中,但尚未推送,不在工作树中。
  2. 您无法忽略已跟踪的文件;.gitignore 只会忽略未跟踪的文件。
- phd
https://stackoverflow.com/search?q=%5Bgit%5D+remove+large+file+history - phd
1个回答

6

先试一下

git rm --cached java_pid66619.hprof

至少你的.gitignore文件会生效。

但是,如果在提交删除操作后,推送仍然失败,则表示(巨大的)文件是以前提交的一部分。
即使您删除并忽略了一个文件,如果它曾经是被推送的历史提交的一部分,这就足以使同样的推送操作因相同原因失败。

那么尝试

git filter-repo --path java_pid66619.hprof --invert-paths

并且进行强制推送。

这使用了新的newren/git-filter-repo,它替代了BFGgit filter-branch

我的上一个提交是该repo的第一次提交,只包含README.md文件。

然后再次克隆仓库,在新的本地克隆的仓库中复制您的文件(减去巨大的文件),添加、提交并推送。


2
我运行了 git rm --cached java_pid66619.hprof 但是出现了错误:fatal: pathspec 'java_pid66619.hprof' did not match any files - Leem
@Leem 没问题。这意味着它已经在 HEAD 中被删除,但可能仍然存在于您正在尝试推送的某个提交中。git filter-repo 将为您摆脱它。为了安全起见,请先保存您的存储库。 - VonC
我的上一个提交是该存储库的第一个提交,仅包含一个README.md文件。 - Leem
我也尝试了 git filter-repo --path java_pid66619.hprof --invert-paths 但是我得到了这个错误信息: git: 'filter-repo' 不是一个 git 命令。请参阅 'git --help'。 - Leem
1
@Leem 是的,您需要首先安装它:https://github.com/newren/git-filter-repo/blob/master/INSTALL.md - VonC
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接