1. 前言

创作开始时间:2021年11月2日16:45:34
2022年6月12日22:48:45

如题,主要讲一下怎么在github上上传超过100M的文件。

2. 正文

1)先安装git lfs服务:

curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs

2)在你的本地git repo运行:

git lfs install
git lfs track * #追踪要上传的大文件,*表示路径下的所有文件
# 注意 * 是所有文件,建议还是specific你想要的

然后就可以正常提交大文件啦!

3. 其他

3.1. Github 的repo settings需要打开lfs按钮

在这里插入图片描述

3.2. LFS是要收费的

Git LFS usage in archives is billed at the same rate as usage with the client. 貌似超过一个G就要收费了。

3.3. LFS取消比较容易失败

由于我是在两台机器上操作,可能是由于我潜在的误操作:

  • 在一台机器上取消了LFS,但是另一台忘记取消了(不确定自己取消了没)
  • github关闭了LFS。
  • 我只运行了git lfs uninstall,没有完全删除。实际上。

然后自己乱操作之后,再push,就发现push不上去了,麻了。

! [remote rejected] master -> master (pre-receive hook declined)

这样的错误。更详细的日志忘了。

貌似最全的git lfs的取消操作:(2022年6月13日01:07:28 错!请参考3.5节,才是最全的取消操作

git lfs uninit

参考:

  • github讨论。https://github.com/git-lfs/git-lfs/issues/910
  • 另外一个参考(uninstall等)https://docs.github.com/en/repositories/working-with-files/managing-large-files/removing-files-from-git-large-file-storage

3.4. 更详细的操作指南

  • https://www.atlassian.com/git/tutorials/git-lfs

3.5. 彻底取消lfs

2022年6月13日00:59:57
lfs真的太坑了。我在了解收费政策之后,直接麻了,超过1g流量直接限制下载。很坑。

哎,删也删不掉。
如附骨之疽,烦死了。

必须删掉lfs,以后再也不用这种坑了。改用zenodo,很香。

最后终于找到了方法:

git lfs uninstall

# results_bears/results_bears_processed_machine_1.tar.lrz  results_bears/results_bears_processed_machine_2.tar.lrz 就是你要删的大文件
git filter-branch --force --index-filter \
      "git rm --cached --ignore-unmatch results_bears/results_bears_processed_machine_1.tar.lrz results_bears/results_bears_processed_machine_2.tar.lrz" \
      --prune-empty --tag-name-filter cat -- --all

然后重新git push origin master -f 就行

看了10多个网页,才找到这一个有用的。很坑。

起作用的参考:

  • https://stackoverflow.com/questions/34579211/how-to-delete-a-file-tracked-by-git-lfs-and-release-the-storage-quota

在这里插入图片描述

没起作用/异常难懂的网页:

  • https://community.atlassian.com/t5/Bitbucket-questions/Delete-Git-LFS-files/qaq-p/863172
  • https://www.jasongaylord.com/blog/2021/08/27/remove-git-lfs-from-repository (git filter-branch没用)
  • https://www.talvbansal.me/blog/remove-git-lfs-from-a-repository/ (只有uninstall,没用)
  • https://stackoverflow.com/questions/52769821/removing-git-lfs(git lfs prune没用)
  • https://stackoverflow.com/questions/48699293/how-to-i-disable-git-lfs(也没用)
  • https://hub.nuaa.cf/git-lfs/git-lfs/issues/3026 (麻烦,也没用)
  • https://docs.github.com/en/repositories/working-with-files/managing-large-files/removing-files-from-git-large-file-storage (filter-branch,没用)

4. 小结

创作结束时间:2022年6月12日22:51:01

先研究到这里把,感觉lfs套路还是挺深的。
2022年6月13日00:19:26

2022年6月13日01:07:01 终于取消了lfs,可以了。

5. 参考文献

  • 如何安装lfs(在ubuntu上)https://stackoverflow.com/questions/48734119/git-lfs-is-not-a-git-command-unclear
  • 怎么使用lfs,怎么提交commit:https://zhuanlan.zhihu.com/p/374650864
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐