gerrit服务器端配置
下载git-lfs插件
- 登录Dashboard [Jenkins] (gerritforge.com),下载对应版本的插件
配置gerrit
-
将下载的lfs.jar插件放到${GERRIT_SITE}/plugins/下面
-
为所有仓库启用git-lfs
-
此步骤需要修改
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
| -
添加LFS配置文件``lfs.config``,写入如下内容
|-------|------------------------------------------------------------------------------------------------|
| 1 2 3 |[lfs ``"^.*"``]
``enabled = ``true
# 启用LFS
``maxObjectSize = 500m ``# LFS允许的最大对象 MiB
| -
提交到
All-projects
仓库并合入变更|-------|------------------------------------------------------------------------------------------|
| 1 2 3 |git add .
git commit -m ``"add lfs config"
git push origin HEAD:refs``/meta/config
|
-
-
在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` |
-
重启gerrit
|---|--------------------------------------------|
| 1 |${GERRIT_SITE}``/bin/gerrit``.sh restart
|
客户端配置
-
安装git-lfs软件包(执行用户需要有sudo权限)
|-----|------------------------------------------------------------------------|
| 1 2 |sudo
apt ``install
-y git-lfs
# 安装成功后可执行git lfs version查看安装的版本
|
客户端使用
-
在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
-
选择要用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
-
查看lfs追踪文件
|---------|---------------------------------------------------------------------------------------------|
| 1 2 3 4 |git lfs ``ls``-files
9a3c7dae41 * example.lfs
d61cf5835a * 2.png
158213f90f * 3.svg
| -
保存并提交配置
|---------|--------------------------------------------------------------------------|
| 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'
|