github大文件上传:使用LFS (以及如何将lfs从仓库中移除!)

本文详细介绍了如何在GitHub上使用Git LFS上传超过100MB的大文件,包括安装步骤和配置。同时,文章讨论了Git LFS的费用问题、取消LFS可能出现的问题及解决办法,提供了一套完整的取消LFS的命令行操作流程,以帮助读者理解和解决相关问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值