在 Gerrit 仓库中创建空分支

.

.

.

.

.

Git 仓库可以创建不带有历史记录的空分支,但 Gerrit 无法直接创建空分支,于是需要通过绕一点弯子来实现。

由于 Gerrit 创建的仓库没有工作空间,所以无法直接创建分支。因此我们需要在 Gerrit 服务器上先克隆一份本地仓库,然后在本地仓库的工作空间中创建空分支,最后绕过 Gerrit 直接将本地仓库的空分支推送到 Gerrit 的原始仓库中,以此来实现创建空分支的目的。

 

在本例中,我们要为 SlideManager.git 仓库创建一个不包含历史记录的空分支:dev-blueberry。

首先登陆 Gerrit 服务器,并来到 git 仓库所在的路径:

>$ ssh gerrit@10.10.10.13
>$ cd xxxx/gerrit/git/xxxx/packages/apps

克隆本地仓库:

>$ git clone SlideManager.git tmp.git
Cloning into 'tmp.git'...
done.

在克隆下来的仓库中创建空分支:

>$ cd tmp.git
>$ git branch -a
*master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/master
  remotes/origin/qa
  remotes/origin/stable
>$ git checkout --orphan dev-blueberry
Switched to a new branch 'dev-blueberry'
>$ cp .gitignore ..
>$ git rm -rf .
>$ mv ../.gitignore .

现在,将空分支提交,并推送给 Gerrit 的本地仓库:

>$ git status
# On branch dev-blueberry
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#    .gitignore
nothing added to commit but untracked files present (use "git add" to track)
>$ git config user.name "root"
>$ git config user.email "gerrit@mail.com"
>$ git add .
>$ git commit -m "New branch for dev blueberry."
>$ git push origin HEAD:dev-blueberry
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 356 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 2 (delta 0)
To /home/gerrit/xxxx/gerrit/git/xxxx/packages/apps/SlideManager.git
 * [new branch]      HEAD -> dev-blueberry

大功告成,去 Gerrit site --> Browse --> Repositories --> Branches 网页刷新一下看看吧,刚创建的新分支应该已经存在了!

 

 

最后,别忘了删掉 Gerrit 服务器上面的临时仓库:

>$ cd ..
>$ rm -rf tmp.git

 

 

 

参考文献:

在GIT中创建一个空分支

 

posted on 2021-06-15 16:56  0xCAFEBABE  阅读(908)  评论(0编辑  收藏  举报

导航