当前位置: 首页 > news >正文

Git LFS 操作处理Github上传大文件操作记录

目录

1、 GitHub上传大文件报错

2、查看大文件提交记录

3、安装 BFG 工具(高效清理 Git 历史大文件)

4、搜索仓库中大于100MB的文件

5、清理历史中的超大文件

 6、CentOS 上安装 Git LFS

6.1、Git LFS安装并初始化

 7、执行操作

 8、不提交大文件


1、 GitHub上传大文件报错

git push -u origin main
Counting objects: 1092, done.
Delta compression using up to 6 threads.
Compressing objects: 100% (975/975), done.
Writing objects: 100% (1092/1092), 504.44 MiB | 4.23 MiB/s, done.
Total 1092 (delta 288), reused 0 (delta 0)
remote: Resolving deltas: 100% (288/288), done.
remote: warning: File workspace/docker/dev-db/zookeeper/log/version-2/log.36 is 64.00 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File workspace/docker/dev-db/zookeeper/log/version-2/log.f4 is 64.00 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File cloud-demo-main/doc/seata-server/lib/rocksdbjni-8.8.1.jar is 58.43 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File workspace/docker/dev-db/zookeeper/log/version-2/log.4a is 64.00 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File workspace/docker/dev-db/zookeeper/log/version-2/log.1 is 64.00 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File workspace/docker/dev-db/zookeeper/log/version-2/log.21 is 64.00 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: error: Trace: 656793fae1dbf2796c07dfe22fc3e3ac6912e4bd81d0283227a3e2ab40b078b7
remote: error: See https://gh.io/lfs for more information.
remote: error: File 000000-local-windows-seata2.0.0-nacos2.3.0.tar.xz is 293.36 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 -
 

2、查看大文件提交记录

find . -type f -size +50M -exec ls -lh {} \;
 

git rev-list --all | xargs -r -l git ls-tree -r --long | sort -uk3 | sort -rnk4 | head -10
 

3、安装 BFG 工具(高效清理 Git 历史大文件)

BFG 比 git filter-branch 更快,适合清理大文件:

wget https://repo1.maven.org/maven2/com/madgag/bfg/1.14.0/bfg-1.14.0.jar
mv bfg-1.14.0.jar /usr/local/bin/bfg.jar
chmod +x /usr/local/bin/bfg.jar

4、搜索仓库中大于100MB的文件

git rev-list --objects --all | grep -E `git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -10 | awk '{print $1}'`

5、清理历史中的超大文件

# 备份仓库(重要!清理历史有风险)
cp -r example example-bak

# 进入仓库目录
cd example

# 使用 BFG 移除指定大文件(替换为你的文件名)java -jar /usr/local/bin/bfg.jar --delete-files "000000-local-windows-seata2.0.0-nacos2.3.0.tar.xz"
java -jar /usr/local/bin/bfg.jar --delete-files "log.1"
java -jar /usr/local/bin/bfg.jar --delete-files "log.f4"
java -jar /usr/local/bin/bfg.jar --delete-files "log.36"
java -jar /usr/local/bin/bfg.jar --delete-files "log.21"
java -jar /usr/local/bin/bfg.jar --delete-files "log.4a"
java -jar /usr/local/bin/bfg.jar --delete-files "rocksdbjni-8.8.1.jar"
java -jar /usr/local/bin/bfg.jar --delete-files "mysql.ibd"
java -jar /usr/local/bin/bfg.jar --delete-files "_c.cfs"
java -jar /usr/local/bin/bfg.jar --delete-files "skywalking-agent.jar"
 


# 清理残留的 Git 垃圾
git reflog expire --expire=now --all && git gc --prune=now --aggressive

git push -f origin main

 6、CentOS 上安装 Git LFS

使用以下命令添加 Git LFS 的软件仓库到系统中。curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash

Generating yum cache for github_git-lfs...
Importing GPG key 0xDC282033:
 Userid     : "https://packagecloud.io/github/git-lfs (https://packagecloud.io/docs#gpg_signing) <support@packagecloud.io>"
 Fingerprint: 6d39 8dbd 30dd 7894 1e2c 4797 fe2a 5f8b dc28 2033
 From       : https://packagecloud.io/github/git-lfs/gpgkey
Generating yum cache for github_git-lfs-source...

The repository is setup! You can now install packages.
 

6.1、Git LFS安装并初始化

sudo yum install git-lfs -y

初始化

 git lfs install
Updated Git hooks.
Git LFS initialized.

 7、执行操作

# 跟踪 .tar.xz、.jar、.log 等大文件类型(根据你的文件类型调整)
git lfs track "*.tar.xz"
git lfs track "*.jar"
git lfs track "*.log"
git lfs track "*.log.*"
git lfs track "*.ibd"
git lfs track "*.cfs"

# 将跟踪规则提交到仓库
git add .gitattributes
git commit -m "Add LFS tracking for large files"


# 确保工作区的大文件已被 LFS 跟踪(会显示 "Git LFS" 标识)
git add .
git commit -m "Fix large files with LFS"

# 强制推送(因为修改了历史,首次需要 -f,注意:协作仓库慎用!)
git push -u origin main -f

 出现报错:

batch response: Git LFS is disabled for this repository.                                                                                                                                                                                    
batch response: Git LFS is disabled for this repository.
batch response: Git LFS is disabled for this repository.
batch response: Git LFS is disabled for this repository.
error: failed to push some refs to 'git
 

8、跟踪文件清理

 git lfs track

git lfs prune

# 查看 LFS 环境信息
git lfs env

# 查看哪些文件被 LFS 跟踪
git lfs status

# 移除所有 LFS 跟踪规则(会修改 .gitattributes 文件)
git lfs untrack "*" 如果不行。换成 

echo "" > .gitattributes
git add .gitattributes
git commit -m "Remove all Git LFS tracking rules"

# 3. 提交 .gitattributes 文件的更改
git add .gitattributes

# 1. 禁用当前仓库的 LFS 钩子

git lfs uninstall #

2. 验证 LFS 是否已卸载(应显示错误)

git lfs env # 输出应类似:git: 'lfs' is not a git command.

 8、不提交大文件

# 1. 查看仓库中占用空间最大的文件(可选步骤,帮助你确定需要删除的大文件)
git verify-pack -v .git/objects/pack/pack-*.idx | sort -k 3 -n | tail -5

# 2. 从提交历史中删除大文件(针对你的具体文件路径)
# 注意:这会重写提交历史,影响所有协作者
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch workspace/docker/dev-db/zookeeper/log/version-2/*' --prune-empty --tag-name-filter cat -- --all

# 3. 删除其他超限文件(根据你的错误信息添加)
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch 000000-local-windows-seata2.0.0-nacos2.3.0.tar.xz' --prune-empty --tag-name-filter cat -- --all
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch cloud-demo-main/doc/seata-server/lib/rocksdbjni-8.8.1.jar' --prune-empty --tag-name-filter cat -- --all

# 4. 添加.gitignore规则,防止未来再次提交大文件
cat << EOF >> .gitignore
# 忽略Zookeeper日志文件
workspace/docker/dev-db/zookeeper/log/

# 忽略超大二进制文件
*.tar.xz
*.jar

# 可根据需要添加更多规则
EOF

# 5. 提交变更并强制推送到远程仓库
git add .gitignore
git commit -m "Remove large files and add .gitignore"
git push -f origin main

http://www.dtcms.com/a/278844.html

相关文章:

  • 终端安全最佳实践
  • sshpass原理详解及自动化运维实践
  • Docker Desktop 挂载本地Win系统配置指南:Redis/MySQL/RabbitMQ持久化与自启设置
  • Kmeams聚类算法详解
  • CSS手写题
  • 精密模具冷却孔内轮廓检测方法探究 —— 激光频率梳 3D 轮廓检测
  • Redis单线程详解
  • H2 与高斯数据库兼容性解决方案:虚拟表与类型处理
  • Ai问答之空间站星等
  • MMKV 存储json list数据(kotlin)
  • Spring Boot 设置滚动日志logback
  • RocketMq部署模式简介
  • 高斯代数基本定理的一种证明
  • 【论文阅读】Thinkless: LLM Learns When to Think
  • Foundry 私钥管理指南:方法与安全最佳实践
  • 《大数据技术原理与应用》实验报告一 熟悉常用的Linux操作和Hadoop操作
  • PHP password_hash() 函数
  • Fiddler——抓取https接口配置
  • 【解决办法】越疆Dobot CR5 桌面客户端DobotStudio Pro连不上机器人
  • 在Ubuntu系统下使用mpstat工具监控CPU性能
  • 深地之下的智慧触角:Deepoc具身智能如何为矿业机器人铸就“感知之核”
  • CSS3 粘性定位解析:position sticky
  • Go从入门到精通(23) - 一个简单web项目-使用数据库存储数据
  • 解决chrome v2 版本插件不支持
  • 上下文管理器 和 contextlib 模块
  • [硬件电路-22]: 为什么模拟电路信号处理运算的精度不如数字信号处理运算?
  • 《Llava:Visual Instruction Tuning》论文精读笔记
  • 基于Chinese-CLIP与ChromaDB的中文图像检索功能实现
  • 人工智能如何重构能源系统以应对气候变化?
  • 动态规划题解——单词拆分【LeetCode】