Download jre-1.8路径: https://www.oracle.com/technetwork/java/javase/downloads/index.html
wget https://gerrit-releases.storage.googleapis.com/gerrit-3.1.3.war
export GERRIT_SITE=~/gerrit_testsite
java -jar gerrit-3.1.3.war init --batch --dev -d $GERRIT_SITE
提示:
参数 --batch 设置gerrit部分参数为默认值,安装一些核心插件等。
--dev 配置gerrit服务器使用默认开发选项。
--d 配置初始化安装路径
命令执行成功结果:
Generating SSH host key ... rsa(simple)... done
Initialized /home/gerrit/gerrit_testsite
Executing /home/gerrit/gerrit_testsite/bin/gerrit.sh start
Starting Gerrit Code Review: OK
如果搭建起来的gerrit服务器,登陆的时候显示的是openid。需要获取openid否则用户不能创建和登陆。可以将配置文件的auth设置为如下:
[gerrit]
basePath = git
canonicalWebUrl = http://ubuntu:8080/
serverId = 12b1048a-e444-48d4-9576-90e17bae2b63
[container]
javaOptions = "-Dflogger.backend_factory=com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance"
javaOptions = "-Dflogger.logging_context=com.google.gerrit.server.logging.LoggingContext#getInstance"
user = jqh
javaHome = /usr/lib/jvm/java-8-openjdk-amd64/jre
[index]
type = lucene
[auth]
type = DEVELOPMENT_BECOME_ANY_ACCOUNT
[receive]
enableSignedPush = false
[sendemail]
smtpServer = localhost
[sshd]
listenAddress = *:29418
[httpd]
listenUrl = http://localhost:8080
[cache]
directory = cache
[plugins]
allowRemoteAdmin = true
那么第一个访问者成为管理者,其他访问者自动成为用户的配置。
git config --file $GERRIT_SITE/etc/gerrit.config httpd.listenUrl 'http://localhost:8080'
$GERRIT_SITE/bin/gerrit.sh restart
http://localhost:8080
或者http://192.168.1.2:8080/
第一个访问的ID将会是管理员账户,后面每新登录一个账户,就会创建一个新ID。
1、命令创建新仓库
shell命令行输入如下创建新工程:
ssh -p 29418 [email protected] gerrit create-project hello.git
其中jqh换成自己的用户名,如果在其他电脑上,127.0.0.1换成目的ip地址192.168.1.2。
2、网页创建新仓库
访问网页:http://192.168.1.2:8080/
通过已有用户名登录,点击“BROWSE”----“Repositories”,
再选择右边的"CREATE NEW",即可创建一个默认的仓库(工程)。
创建fuchsia_仓库,示例如下:(其中create initial empty commit选项,false-无commit记录,true-有初始化commit记录)
创建自带git log记录的已有仓库时,请选择false。我这里选择false。
1,首先需要在gerrit上创建一个空仓库不带日志记录的空仓库。
方法一:
如上一步网页创建新仓库。
方法二:
使用命令行 ssh -p 29418 admin@localhost gerrit create-project fuchsia_.git
2,然后
克隆已有仓库,并进入该目录
git clone /home/zeos/fuchsia;cd fuchsia;
配置gerrit仓库权限
git push -o skip-validation ssh://[email protected]:29418/fuchsia_.git *:*
ssh -p 29418 review.example.com gerrit create-branch myproject newbranch master
为了用户能够将修改内容提交推送到本gerrit服务器,需要管理员对该仓库做如下配置:(其中require change-id in commit messge选择false)
ssh -p 29418 admin@localhost gerrit xxx
比如创建项目:ssh -p 29418 admin@localhost gerrit create-project test.git
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub
将生成的公钥拷贝到new ssh key框内,然后点击“ADD NEW SSH KEY”。
同一台电脑:
git clone ssh://jqh@localhost:29418/fuchsia.git
x服务器:
git clone ssh://[email protected]:29418/fuchsia_.git
其他用户克隆的时候,将jqh换成自己用户名即可。
推送前确认自己用户的git全局配置,主要关注用户名和邮件,查看全局信息:
git config --list
git config --global user.name “github’s Name”
git config --global user.email “[email protected]”
git push origin HEAD:refs/for/master