Git是目前最流行的分布式版本控制系统,而Gerrit是一种免费、开放源代码的代码审查软件,使用网页界面。利用浏览器,同一个团队的软件程序员,能够相互审阅彼此修改后的程序代码,决定是否可以提交,退回或者继续修改。它使用Git做为底层版本控制系统。趁着作测试的机会,简单学习了解一下Git+Gerrit是如何搭建使用的,顺便简单作个小笔记。html
系统环境:Ubuntu12.04 Server 64java
安装Gitmysql
$sudo su - ##切换到root帐户环境下(我的习惯)git
#apt-get update程序员
#apt-get install git-core ##一条命令就能够吧Git搞定了~sql
# git --help ##Git的相关命令数据库
usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]vim
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]浏览器
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]oracle
[-c name=value] [--help]
<command> [<args>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
安装Gerrit
Gerrit是由Java开发的,被封装为一个war包,因此须要Java环境。
#java --version ##看一下Java是否被安装配置好
默认安装的OpenJDK,可是当时的同事说推荐仍是用Oracle JDK,使用最新的稳定版本 Oracel JDK7
安装配置Oracel JDK7
#apt-get install oracle-java7-installer
#update-alternatives --config java
#vim /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
JAVA_HOME="/usr/lib/jvm/java-7-oracle"
#source /etc/environment
#echo $JAVA_HOME
安装配置Mysql数据库
这里也可使用H2或者PostgreSQL数据库均可以。
#apt-get install mysql-server ##默认密码为空,记得为root设置一个密码,可使用mysqladmin命令来设置
#mysql -u root -p
mysql>CREATE USER 'gerrit2'@'localhost' IDENTIFIED BY 'password';
mysql>CREATE DATABASE reviewdb;
mysql>ALTER DATABASE reviewdb charset=latin1;
mysql>GRANT ALL ON reviewdb.* TO 'gerrit2'@'localhost';
mysql>FLUSH PRIVILEGES;
建立gerrit2帐户并下载初始化配置Gerrit
我下载的是gerrit-2.7-rcl.war
#adduser gerrit2 ##建立gerrit2帐户
#sudo su gerrit2
由于我都已经初始化设置过Gerrit,因此下面的显示结果是我又从新再执行一次命令以后的显示结果:
$java -jar gerrit-2.7-rc1.war init -d ~/gerrit_testsite
*** Gerrit Code Review 2.7-rc1
***
*** Git Repositories
***
Location of Git repositories [test]: ##指定Git库的位置,test就是Git的库的位置
*** SQL Database
***
Database server type [mysql]:
Server hostname [127.0.0.1]:
Server port [3306]:
Database name [reviewdb]: ##指定以前建立的数据库
Database username [gerrit2]:
Change gerrit2's password [y/N]?
*** User Authentication
***
Authentication method [LDAP/?]: ##使用Windos AD域控做为认证
LDAP server [ldap://10.100.2.75]:
LDAP username [gerrit]:
Change gerrit's password [y/N]?
Account BaseDN [dc=test,dc=com]:
Group BaseDN [dc=test,dc=com]:
*** Email Delivery
***
SMTP server hostname [localhost]:
SMTP server port [(default)]:
SMTP encryption [NONE/?]:
SMTP username :
*** Container Process
***
Run as [gerrit2]:
Java runtime [/usr/lib/jvm/java-7-oracle]:
Upgrade /home/gerrit2/gerrit_testsite/bin/gerrit.war [Y/n]?
Copying gerrit.war to /home/gerrit2/gerrit_testsite/bin/gerrit.war
*** SSH Daemon
***
Listen on address [*]:
Listen on port [29418]:
*** HTTP Daemon
***
Behind reverse proxy [Y/n]?
Proxy uses SSL (https://) [y/N]?
Subdirectory on proxy server []:
Listen on address [10.100.2.201]:
Listen on port [8080]:
Canonical URL [http://10.100.2.201:8080]:
*** Plugins
***
Prompt to install core plugins [y/N]? y
Install plugin reviewnotes version 2.7-rc1 [y/N]? y
version 2.7-rc1 is already installed, overwrite it [y/N]? y
Install plugin commit-message-length-validator version 2.7-rc1 [y/N]? y
version 2.7-rc1 is already installed, overwrite it [y/N]? y
Install plugin replication version 2.7-rc1 [y/N]? y
version 2.7-rc1 is already installed, overwrite it [y/N]? y
Initialized /home/gerrit2/gerrit_testsite
$cd /home/gerrit2/gerrit_testsite/bin/
$./gerrit.sh start ##可使用它自带的脚原本启动和中止Gerrit服务
$cd /home/gerrit2/gerrit_testsite/etc ##上面的一些配置能够在这里再作修改
登录访问Gerrit
打开浏览器使用测试机域控制器上的test帐号就能够登录访问Gerrit了
在Web上面就能够直接建立项目,管理权限之类的,还在学习中~
第一次登录Gerrit帐户的AD帐号是管理员帐号~
有问题多多指教,但愿能和你们多学习多交流。