POST git-receive-pack 后 git push 挂起并失败

时间:2021-05-11 20:14:01

标签: git gitignore git-lfs

我正在尝试推送我的存储库,其中包含很多我可以忽略的 .png.mp4.h5 文件。

目录结构:

.gitignore
CV PROJECT
├───.vscode
├───Docker
├───src
│   ├───Game
│   ├───Main
│   │   └───__pycache__  
│   └───Video
│       ├───Images       
│       │   ├───test    
│       │   │   ├───boost # dir that has .png files 
│       │   │   ├───click # dir that has .png files 
│       │   │   └───upgrade # dir that has .png files 
│       │   └───train  
│       │       ├───boost # dir that has .png files 
│       │       ├───click # dir that, has .png files 
│       │       └───upgrade # dir that has .png files 
│       ├───Models # dir that has .h5 files  
│       └───Videos
│           ├───boost # dir that has .mp4 files
│           ├───click # dir that has .mp4 files
│           └───upgrade # dir that has .mp4 files
└───Tutorial
    └───.ipynb_checkpoints

tl;dr我的.gitignore应该是什么样子的?


命令:

git config --global http.postBuffer 2048M
git config --global http.maxRequestBuffer 1024M
git config --global core.compression 9

git config --global ssh.postBuffer 2048M
git config --global ssh.maxRequestBuffer 1024M

git config --global pack.windowMemory 256m 
git config --global pack.packSizeLimit 256m

# git hangs here
git push --verbose -f origin master

输出:

git 挂在这里:

Total 133 (delta 29), reused 0 (delta 0), pack-reused 0
POST git-receive-pack (569667108 bytes)

所以我试图用这个 .gitignore 忽略它们:

*.mp4
*.h5


Models/*
Videos/*
test/*
train/*

boost/*
upgrade/*
click/*

并得到这个输出:

remote: Resolving deltas: 100% (20/20), completed with 1 local object.
remote: warning: File src/Video/Videos/boost/b7.mp4 is 57.86 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File src/Video/Videos/click/c7.mp4 is 73.08 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File src/Video/Videos/upgrade/u6.mp4 is 56.50 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: 3a803801864c0608c9e57dd7cf9d3ee3eaca6a180713b3c7119e8b0414c776ee
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File src/Video/medmodel.h5 is 112.78 MB; this exceeds GitHub's file size limit of 100.00 MB
To https://github.com/romhayh/special-mario.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/romhayh/special-mario.git'

在此之后,我将 .gitignore 转换为 .gitattributes(不使用 git lfs track)并得到相同的错误消息:

remote: Resolving deltas: 100% (29/29), completed with 1 local object.
remote: warning: File src/Video/Videos/boost/b7.mp4 is 57.86 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File src/Video/Videos/click/c7.mp4 is 73.08 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File src/Video/Videos/upgrade/u6.mp4 is 56.50 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: 9add1b6eba287591037b40a5a483a1b7bb9d2746853150a2146bdf83b8e58b9c
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File src/Video/Models/medmodel.h5 is 112.78 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File src/Video/medmodel.h5 is 112.78 MB; this exceeds GitHub's file size limit of 100.00 MB

1 个答案:

答案 0 :(得分:1)

一个好的现实世界的类比在这里很棘手,但假设您有一个水泥送货服务。您向某个客户交付了 1000 立方码的水泥,这些水泥现已凝固。您的客户打电话给您,说他们不想要那么多水泥:他们只想要 10 立方码。所以你让你的卡车再运送 10 码水泥。你是否改善了他们的情况,或者只是让情况变得更糟?

现在,上述类比的原因很简单:Git 只提交向存储库添加新内容。如果你把一个大文件放到某个提交中,那个大文件永远在那个提交中。如果有人不想要那个巨大的文件,而你做了一个 提交而 缺少 这个巨大文件,那么,现在你有 两次 提交: 一个有大文件,一个没有。第二次提交依赖于,因此需要第一次提交

不管你做什么,如果你不断增加新的提交,你只会让一切变得更糟。你需要的不是更多的水泥(呃,承诺)。您需要某种手提钻和去除水泥的服务(从您的存储库中删除提交的东西)。

但这还不是全部!虽然我们已经看到在 .gitignore 中列出文件对任何现有提交都没有影响 - 根本没有现有提交可以更改;你只需要把它们拖走并完全停止使用它们来摆脱它们——这对提交也没有什么好处,至少还没有。如果一个文件被跟踪,它对未来提交的文件也没有影响。

所以:

  • 你的第一份工作是删除一些提交。我们通常使用 git reset 执行此操作。 git reset 命令具有破坏性!在这里要非常小心:您可能应该使用克隆存储库,而不是原始存储库。

  • 然后,删除错误提交后,您可能需要显式删除大文件,以便不再跟踪。如果文件在 Git 的索引中,则该文件在 Git 中被跟踪。你怎么知道一个文件是否在 Git 的索引中?嗯,你知道,因为它被跟踪。如您所见,这是一个循环问题。 :-) 但是如果你肯定希望它被跟踪,你可以运行:

    git rm --cached src/Video/Videos/boost/b7.mp4
    

    例如(对于名为 src/Video/Videos/boost/b7.mp4 的文件)。这将从 Git 的索引中删除文件,如果它 Git 的索引中(被跟踪),或者如果文件不在 Git 中,则会给你一个关于文件不在 Git 中的错误 出现在 Git 的索引中(未跟踪)。因此,无论哪种方式,您现在都可以确定该文件未跟踪

当一个文件未被跟踪时,git status通常会抱怨它。 .gitignore 列表让 git status 闭嘴。这通常是 .gitignore 的主要功能:使 git status 表现。另一个特点是,只要当前没有跟踪某个文件,在.gitignore中列出该文件意味着git add --allgit add *不会 将其添加到 Git 的索引中,以便对其进行跟踪。

某些文件的跟踪性并不是您设置一次就忘记的东西。因为提交是不可更改的,一旦您进行了一些提交并且该提交确实在其中包含该文件,那么任何时候您使用 git checkout提取 提交,文件进入 Git 的索引,因此再次被跟踪。您可以使用 git rm --cached 取消跟踪文件,这样它就不会进入您所做的 new 提交。但是你不能从现有的提交中删除它,永远:没有现有提交可以永远改变

你必须做的是删除错误提交,然后不再提交文件

如果你想这样做,你可以将文件放入 Git-LFS。 (Git-LFS 有它自己的怪癖和怪癖。我只是因为你提出了这一点,使用 标签并在你的问题中提到了 LFS。)但是你必须摆脱现有的提交里面有大文件。只有您可以说出哪些是提交,因为这些提交在 您的 存储库中,而其他人没有。

这就是为什么我建议您先克隆现有存储库,然后再尝试删除任何错误提交。但是,您可能会在这里找到一些更有用的其他工具和/或方法。参见,例如,How to remove/delete a large file from commit history in Git repository?