github push 超过 100M pdf 文件提示错误,.gitignore 无法忽视*.pdf 文件求助

2017-02-24 10:46:53 +08:00
 stringtheory
latex 排版的论文,.gitignore 里已经添加*.pdf 希望让 pdf 不上传了, github 还是自动会在 push origin dev 或 master 时自动上传 main.pdf ,最近因为 main.pdf 超过 100M 了,所以每次上传超慢,而且会提示:
remote: error: File main.pdf is 100.08 MB; this exceeds GitHub's file size limit of 100.00 MB

按照 https://help.github.com/articles/removing-files-from-a-repository-s-history/ 的说明:
依次使用命令:
git rm --cached main.pdf
git commit --amend -CHEAD
git push origin dev
好像还是会报错:
remote: error: File main.pdf is 100.08 MB; this exceeds GitHub's file size limit of 100.00 MB

请问这种情况该怎么办?
谢谢!
3853 次点击
所在节点    git
14 条回复
stringtheory
2017-02-24 11:11:59 +08:00
悲剧的是,按照这个帖子 http://www.ifeegoo.com/git-code-management-dot-gitignore-file-has-no-effect-solution.html#comment-1228
试了一下
git rm -r --cached .
然后 git add .
git commit -a -m 'msg'
然后 git push origin dev 提示:

Counting objects: 40, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (40/40), done.
Connection reset by 192.30.253.1138 MiB | 13.00 KiB/s
fatal: The remote end hung up unexpectedly14.00 KiB/s
fatal: sha1 file '<stdout>' write error: Broken pipe
error: failed to push some refs to 'git@github.com:***/***.git'
otakustay
2017-02-24 12:05:08 +08:00
你在添加 gitignore 之前 pdf 是不是已经 add 和 commit 过了?
kevinyoung
2017-02-24 12:13:20 +08:00
我来给个方案,在目录的 Makefile 里面添上这么一句:

clean:
rm -f *.pdf *.out *.toc *.aux *.log *.nav *.snm *.bbl *.blg *.dvi *.bcf *.xml

每次提交之前都来个 make clean ,这样生成的东西就都没了,目录下面干干净净的只剩文本了
xjp
2017-02-24 12:23:17 +08:00
gitignore 不会忽略已经添加到版本管理里的文件 删除仓库里的文件后 gitignore 才会生效
SpicyCat
2017-02-24 12:39:50 +08:00
git filter-branch --index-filter 'git rm --cached --ignore-unmatch path/to/your/file.pdf' HEAD
yushiro
2017-02-24 13:16:43 +08:00
你需要 bfg ,专门用来删除 git 历史记录的文件。
具体的请 google , bfg 的官网有详细的教程
shalk
2017-02-24 13:32:48 +08:00
msg7086
2017-02-25 08:45:46 +08:00
每次遇到这种帖子,我都毫不犹豫推荐下载一份 SmartGit 自己看看仓库里有点什么东西再说。
如果你不熟悉 Git ,为什么不让图形界面帮你一下呢。
matsuz
2017-02-25 11:31:18 +08:00
commit 之前 git status 看看添加了哪些文件
stringtheory
2017-02-25 23:23:11 +08:00
@otakustay 可能是的
stringtheory
2017-02-25 23:29:57 +08:00
谢谢楼上各位,我再试试看。
stringtheory
2017-02-26 11:04:35 +08:00
在 dev 分支下使用了命令:
$ git filter-branch --index-filter 'git rm --cached --ignore-unmatch main.pdf' HEAD
提示很多类似如下:
Rewrite *** (72 seconds passed, remaining 0 predicted) rm 'main.pdf'
所以应该是把各个历史上的 pdf 都删掉了。
然后$ git status
On branch dev
Your branch and 'origin/dev' have diverged,
and have 206 and 200 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean
我的理解是既然本地已经把 pdf 删了,远程 github 上就不要再 pull 回来 merge 了。于是就直接:
$ git push origin dev
To git@github.com:XXX/XXX.git
! [rejected] dev -> dev (non-fast-forward)
error: failed to push some refs to 'git@github.com:XXX/XXX.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
查了查说因为版本落后,所以不能直接 push ,只好强制:
$ git push -u origin dev -f
Counting objects: 1262, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (1261/1261), done.
Connection reset by 192.30.253.11340.56 MiB | 11.00 KiB/s
fatal: The remote end hung up unexpectedlyB | 11.00 KiB/s
fatal: sha1 file '<stdout>' write error: Broken pipe
error: failed to push some refs to 'git@github.com:XXX/XXX.git'

不太明白这是成功了吗,还是需要重新钥匙配对认证?
SpicyCat
2017-02-27 10:44:23 +08:00
@stringtheory #12 在做 filter-branch 操作的时候,确保你本地是最新的。当你删除 PDF 文件后,你本地的 git repo 和 remote 就不一致了,所以直接 push 是不行的,需要加 -f 参数。
然而,有些 git 系统,比如 github 和 gitlab, 可以默认设置了保护主分支,就是不能用 -f 来强制 push 。
你最好检查一下有没有这样的设置。
不过你这里报错似乎是网络问题?
你在 git push -f 一次试试看
stringtheory
2017-03-01 09:38:11 +08:00
@SpicyCat 谢谢回复, git status 是说 nothing to commit ,所以就没更新本地。不知道是不是网络问题,暂时试了试建立一个新分支 hotfix 过渡用着, hotfix 更新倒是没再遇到网络问题。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/342845

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX