1:搭建gerrit服务器端
downloadgerrit-2.10.war
install java:
sudo apt-get install openjdk-7-jre-headless
install gerrit:
java -jar gerrit-2.10.war init -d review_site
vim review_site/etc/gerrit.config
[gerrit]
basePath = git
canonicalWebUrl=http://10.0.7.233:8081//*根据你服务器实际的IP地址填写*/
[database]
type = h2
database = db/ReviewDB
[index]
type = LUCENE
[auth]
type = HTTP
[sendemail]
smtpServer = localhost
[container]
user = ofi
javaHome= /usr/lib/jvm/java-7-openjdk-amd64/jre
[sshd]
listenAddress = *:29418
[httpd]
listenUrl = proxy-http://*:8081//*反向代理,必须*/
[cache]
directory = cache
./review_site/bin/gerrit.sh restart
install apache2:
sudo apt-get install apache2
in /etc/apache2/apache2.conf addInclude httpd.conf
httpd.conf文件的内容如下,红色部分根据你实际情况填写:ServerName localhost
<VirtualHost *:8080>
ProxyRequests Off
ProxyVia Off
ProxyPreserveHost On
AllowEncodedSlashes On
RewriteEngine On
http://10.0.7.233:8081/$1 [NE,P]
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /login/>
AuthType Basic
AuthName "Gerrit CodeReview"
Require valid-user
AuthBasicProvider file
/home/ofi/gerrit/review_site/etc/passwd
</Location>
ProxyPass / http://10.0.7.233:8081/
</VirtualHost>
in /etc/apache2/ports.conf add:
NameVirtualHost *:80
NameVirtualHost *:8080
Listen 80
Listen 8080
建立一些apache2文件的链接:
cd /etc/apache2/mods-enabled
ln -s ../mods-available/proxy.load
ln -s ../mods-available/proxy.conf
ln -s ../mods-available/proxy_http.load
ln -s ../mods-available/proxy_balancer.conf
ln -s ../mods-available/proxy_balancer.load
ln -s ../mods-available/rewrite.load
ln -s ../mods-available/ssl.conf
ln -s ../mods-available/ssl.load
创建gerrit账号:
touch ./review_site/etc/passwd
htpasswd -b ./review_site/etc/passwd ofi 123456
the first user is admin, if you want to add other user, use:
htpasswd -b ./review_site/etc/passwduser_namepassword
gerrit startup:
./review_site/bin/gerrit.sh stop
./review_site/bin/gerrit.sh restart
apache startup:
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 restart
2:客户使用gerrit
loginhttp://10.0.7.233:8080/*根据你实际情况而定*/
settings -->contact information, add yourfull name
右上角显示你刚刚填写的Full Name
settings -->SSH Public Keys, add your public keys
how to get your public keys? in your linux machine:
run:
ssh-keygen
cat ~/.ssh/id_rsa.pub
to get your Public Keys.
Admin can create new project in
Gerrit website→ Projects→ Create New Project
Select your new project, click Branchs , you can add branchs in yourproject.
elect your new project, click General, you can find the clone addr ofyour Project, copy it, in your linux machine, run it, you can down load thecode.
For example:
git clone ssh://ofi@10.0.7.233:29418/ofi_test && scp -p -P 29418ofi@10.0.7.233:hooks/commit-msg ofi_test/.git/hooks/
cd ofi_test/
git branch -a
git checkout -b test origin/test2
git pull–rebase
git config --global user.name“your name”
git config --global user.email “your email”
modify your xxx.c
git status
git add xxx.c
git commit -m“your commit message”
git commit–amend -s
git push origin HEAD:refs/for/test2
实际操作:
上面图片放大:
解决方法:
In /etc/ssh/ssh_config, add
StrictHostKeyChecking no
解决后:
修改代码,上传代码前准备阶段。增加一个test.c文件为例子,如果在已有问价上修改,方法也是一样的。同时确保自己设置了:
git config --global user.name “your name”
git config --global user.email “your email”
设置的user.name,user.email都会在自己的commit中显示出来。
git add操作之前,可以先用git status先看看自己改了那些文件。最好是一个文件做一个commit。
上传代码操作:
遇到一些error,怎么解决?在gerrit服务器端,添加test2branch的Forge Author/Committer Identity
上面红色框里面的test,实际上是个group。由服务器端People--》Create NewGroup创建。可以在Group里面加入gerrit成员,设定权限。
改完后,成功push代码:
对自己上传的代码增加reviewer:
reviewer 在自己的账号下review patch(My -> Changes目录下):
Code-Review+2
reviewer将代码提交到服务器:
其他人更新下代码,就可以看到你的code了:
相关commit message: