git push失败:存在超过100MB的文件

报错原因:

commit的文件list中存在大文件,导致无法push

remote: warning: File logs/unsup-Stack/DyHATR_small_0.001000/entity2vec is 89.35 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: error: Trace: 5e559a5e91ec5f06951b01b4d72e4c1a87133a05a84126141d2ade0dc75f773f
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File dataset/dblp/dblp.xml is 2941.48 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
To https://github.com/qycss/DHEmbedding.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/qycss/DHEmbedding.git'

解决方法:

移除本次commit中的大文件

1. 移除大文件

从报错信息中查找哪些文件出错,然后使用命令git rm --cached 删除指定文件

  • File logs/unsup-Stack/DyHATR_small_0.001000/entity2vec is 89.35 MB
    • $ git rm --cached logs/unsup-Stack/DyHATR_small_0.001000/entity2vec
  • File dataset/dblp/dblp.xml is 2941.48 MB; this exceeds GitHub’s file size limit of 100.00 MB
    • $ git rm --cached dataset/dblp/dblp.xml

或者使用命令 find ./ -size +100M 查询所有大于100MB的文件

$ find ./ -size +100M
./.git/objects/pack/pack-3492a80b3ed78f8a83a2a1f8fd206e011fc9ee74.pack
./dataset/dblp/dblp.xml

rm后的状态:

$ git status

On branch master
Changes to be committed:
  (use "git restore --staged ..." to unstage)
        deleted:    dataset/dblp/dblp.xml
        deleted:    logs/unsup-Stack/DyHATR_small_0.001000/entity2vec

Untracked files:
  (use "git add ..." to include in what will be committed)
        dataset/dblp/dblp.xml
        logs/unsup-Stack/DyHATR_small_0.001000/entity2vec

2. 重新提交

编辑commit log,完成后:wq保存退出

git commit --amend

此时的状态为:

$ git status
On branch master
Untracked files:
  (use "git add ..." to include in what will be committed)
        dataset/dblp/dblp.xml
        logs/unsup-Stack/DyHATR_small_0.001000/entity2vec

nothing added to commit but untracked files present (use "git add" to track)

然后正常 git push 即可

如果上述操作完成后还是无法解决问题,则可以运行如下命令删除有关某个文件的push操作:

git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch '

最后使用命令git gc 清除本地仓库缓存

你可能感兴趣的:(git,git,github)