gerrit配置及使用git-lfs

gerrit服务器端配置

下载git-lfs插件

  1. 登录Dashboard [Jenkins] (gerritforge.com),下载对应版本的插件

配置gerrit

  1. 将下载的lfs.jar插件放到${GERRIT_SITE}/plugins/下面

  2. 为所有仓库启用git-lfs

    1. 此步骤需要修改 All-projects 仓库配置,步骤如下 1、克隆仓库,检出到refs/meta/config

      |---------|---------------------------------------------------------------------------------------------------------------------------------------------------|
      | 1 2 3 4 | git clone ``"ssh://[email protected]:29418/All-Projects" cd All-Projects git fetch origin refs``/meta/config git checkout FETCH_HEAD |

    2. 添加LFS配置文件``lfs.config``,写入如下内容

      |-------|------------------------------------------------------------------------------------------------|
      | 1 2 3 | [lfs ``"^.*"``] ``enabled = ``true # 启用LFS ``maxObjectSize = 500m ``# LFS允许的最大对象 MiB |

    3. 提交到 All-projects 仓库并合入变更

      |-------|------------------------------------------------------------------------------------------|
      | 1 2 3 | git add . git commit -m ``"add lfs config" git push origin HEAD:refs``/meta/config |

  3. 在gerrit.config中启用lfs,在gerrit.config中增加如下内容

    |-----|---------------------------|
    | 1 2 | [lfs] ``plugin = lfs |

复制代码
      指定存储类型,在${GERRIT_SITE}/etc下增加lfs.config,写入以下内容(如不填写directory的值则默认会将lfs文件的数据保存在$GERRIT_SITE/data/lfs)

  |-----|-------------------------------|
  | 1 2 | `[storage]` ` ``backend = fs` |
  1. 重启gerrit

    |---|--------------------------------------------|
    | 1 | ${GERRIT_SITE}``/bin/gerrit``.sh restart |

客户端配置

  1. 安装git-lfs软件包(执行用户需要有sudo权限)

    |-----|------------------------------------------------------------------------|
    | 1 2 | sudo apt ``install -y git-lfs # 安装成功后可执行git lfs version查看安装的版本 |

客户端使用

  1. 在Git仓库中为仓库设置相关配置

    |---|---------------------|
    | 1 | git lfs ``install |

    Tips:

    这个命令会自动改变Git配置文件 .gitconfig,而且是全局性质的,只需要配置一次,会自动在配置文件中增加如下配置:

    filter "lfs"

    clean = git-lfs clean -- %f

    smudge = git-lfs smudge -- %f

    process = git-lfs filter-process

    required = true

  2. 选择要用LFS追踪的文件

    |---------|---------------------------------------------------------------------------------------------------|
    | 1 2 3 4 | git lfs track ``"*.svg" # 或者具体到某个文件 git lfs track ``"2.png" git lfs track ``"example.lfs" |

    Tips:

    这个命令会更改仓库中的 .gitattributes配置文件(如果之前不存在这个文件,则会自动新建):

    查看如下:

    $ cat .gitattributes

    *.svg filter=lfs diff=lfs merge=lfs -text

    2.png filter=lfs diff=lfs merge=lfs -text

    example.lfs filter=lfs diff=lfs merge=lfs -text

  3. 查看lfs追踪文件

    |---------|---------------------------------------------------------------------------------------------|
    | 1 2 3 4 | git lfs ``ls``-files 9a3c7dae41 * example.lfs d61cf5835a * 2.png 158213f90f * 3.svg |

  4. 保存并提交配置

    |---------|--------------------------------------------------------------------------|
    | 1 2 3 4 | # 提交 git add . git commit -m ``"add Large File Storage" git push |

    注意:

    如git仓库中配置了使用lfs来管理大文件,则在repo sync之后执行以下命令拉取大文件

|---|-----------------------------------|
| 1 | repo forall -c ``'git lfs pull' |

相关推荐
码见愁39 分钟前
Git分布式版本控制工具
分布式·git
程序猿chen1 小时前
JVM考古现场(十九):量子封神·用鸿蒙编译器重铸天道法则
java·jvm·git·后端·程序人生·java-ee·restful
混血哲谈1 小时前
如何安装git?
git
仙人掌_lz4 小时前
如何在本地使用Ollama运行 Hugging Face 模型
java·人工智能·servlet·ai·大模型·llm·ollama
得物技术5 小时前
如何合理规划Elasticsearch的索引|得物技术
elasticsearch
我爱布朗熊5 小时前
5.Elasticsearch - Spring Data 框架
spring·elasticsearch·jenkins
尸僵打怪兽5 小时前
gitee基本使用
git·gitee·git使用
阿里云大数据AI技术6 小时前
阿里云 Elasticsearch Serverless 检索增强型8.17版免费邀测!
大数据·elasticsearch
冰凌糕8 小时前
Git 远程仓库
git·版本控制
Ring__Rain8 小时前
visual studio 常用的快捷键(已经熟悉的就不记录了)
c++·git·visual studio