突然发现git已经5G了. 咋办呢?

git情况

  • 原始git
  • 全库5G
  • 文件1.31G
  • 整理后git
  • 全库10G
  • 文件35.2m
  • 整理后新clone
  • 全库2.4G
  • 新库重建后
    • 全库600m

思路

  1. 本地整理一个新的branch
  2. 这个branch提交到另一个git remote

步骤

# 安装大文件git
brew install git-lfs

# 本地复制一份git, 直接复制就可以了

# 然后在备用目录里面, 大文件处理
git lfs migrate import --everything --above=3000Kb

# 远程新建一个项目, 顺便吐槽官网文档, 官方说明竟然让我们直接push -f, 这是疯了吗? 所有人都不能正常拉取了.

# 添加到本地, 注意此处默认是恶心的http

git remote add tt git@codeup.aliyun.com:5f17b582df9df74e36afafdf/algorithm/pdk2.git

# todo 需要添加扩展名lbs监控

# 拿整理好的git项目
# 如果此时没有安装lfs, 那么安装大文件git
brew install git-lfs
# 然后clone新项目
git  clone git@codeup.aliyun.com:5f17b582df9df74e36afafdf/algorithm/pdc3.git
# 进入目录执行以下下面这个, 支持大文件提交
git lfs install

# 注意此时不要git lfs clone, git已经更新了直接git clone就OK了

# 测试效果
git lfs prune --dry-run
# 定期运行 命令是保持本地仓库大小减小的好主意
git lfs prune 


记录时间

  • 11:01
    • 开始git
  • 11:08
    • 开始push到新的项目
  • 11:15
    • 66%
  • 11:45
    • 开始clone
  • 11:49
    • clone 结束

lfs 超越 gitattributes

https://stackoverflow.com/questions/60029570/does-git-lfs-track-do-more-than-writing-to-gitattributes

  • 直接改gitattributes没毛病
  • 原文:
  • git lfs track does two things: modify .gitattributes and adjust timestamps so that Git picks up any existing files and converts them to LFS objects. In addition, it does some sanity-checking to avoid duplicates and common mistakes.
  • There’s no reason you can’t just modify .gitattributes yourself, but note that if you do that, you should also run git add –renormalize . to make sure that any existing files matching the relevant patterns are converted to LFS.

参考

https://help.aliyun.com/document_detail/206889.htm?spm=a2c4g.11186623.0.0.10f746e4uw5m5z#topic-2042160
https://github.com/git-lfs/git-lfs/issues/282
# 安装大文件git
brew install git-lfs
# 搞本地的大文件提交, 设置为3m比较合理
git lfs migrate import --everything --above=3000Kb



# 查看git lfs控制内容
git lfs track
# 这个命令其实等于直接查看: .gitattributes

# 设置所有>3000k都走lfs todo 要看
project_root/.git/config
track-large = !"git st --porcelain --ignore-submodules | grep -v \"D \" | awk '{ l=length($0); s=substr($0,4,l-1); print s}' | sed -n 's/\\(\\(.* -> *\\)\\|\\)\\(.*\\)/\\3/p' | xargs -I{} find {} -size +300k | xargs -I{} git lfs track \"{}\""

# 明天思路
- 本地复制一份.
- 清理之后提交到远程另一个库
- clone下来, 看尺寸
- 不对, 还是要copy这个pback文件夹, 避免重复传文件

参考

  • https://help.aliyun.com/document_detail/206889.htm?spm=a2c4g.11186623.0.0.10f746e4uw5m5z#topic-2042160