一、前期准备
$ git config --global user.name "Firstname Lastname"
$ git config --global user.email "your_email@youremail.com"
$ pip install git-review
1). 备份.ssh (如果存在):
myubuntu@host:~$ cp -r ~/.ssh ~/.ssh_bak
2). 生成密钥:
myubuntu@host:~$ rm -rf ~/.ssh
myubuntu@host:~$ ssh-keygen -t rsa -C "gerrit上的注册邮箱"
myubuntu@host:~$ cat ~/.ssh/id_rsa.pub
复制该公钥到gerrit的setting中
3). 添加到ssh-agent中
- start the ssh-agent in the background
$ eval "$(ssh-agent -s)"
Agent pid 59566
- add your SSH private key to the ssh-agent.
$ ssh-add ~/.ssh/id_rsa
4). 测试
$ ssh -T git@github.com
Hi Iruze! You've successfully authenticated, but GitHub does not provide shell access.
或参考:https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
二、工作流程
- 获取项目代码
myubuntu@host:~$ git clone git://github.com/openstack/nova.git
myubuntu@host:~$ cd nova
- 创建版本库
$ git init
Initialized empty Git repository in /Users/michael/learngit/.git/
- 检查git-review是否可以提交review
myubuntu@host:~$ git review -s
测试29418端口是否可以通信
$ ssh -vv -p 29418 xxx@review.openstack.org
- 如果没有添加远程仓库
myubuntu@host:~$ git remote add gerrit ssh://**"username"**@review.openstack.org:29418/openstack/nova.git
myubuntu@host:~$ git remote -v
(git remote remove origin 移除源,或许用到)
- 创建新的分支,在其上修改,之后提交
myubuntu@host:~$ git checkout -b "dev"
myubuntu@host:~$ git status
(…修改xxx文件之后…)
(在cd nova最外层文件内)
myubuntu@host:~$ git status
myubuntu@host:~$ git add xxx
myubuntu@host:~$ git commit -m "fix yyy problem in xxx file"
- tox检查提交
如果是上次提交的一个patch:
myubuntu@host:~$ git commit --amend
myubuntu@host:~$ tox -v #(check code)
(or maybe ) tox -e pep8/py27/py35/py36/docs
最终正式提交
myubuntu@host:~$ git review [branch_name]
三、其他错误
1)无法ping通github.com
解决:
- vi /etc/hosts
- 在最后添加:
192.30.253.113 github.com
192.30.252.131 github.com
185.31.16.185 github.global.ssl.fastly.net
74.125.237.1 dl-ssl.google.com
173.194.127.200 groups.google.com
192.30.252.131 github.com
185.31.16.185 github.global.ssl.fastly.net
74.125.128.95 ajax.googleapis.com
Reference:
Gerrit工作流程:
https://blog.csdn.net/Shatty/article/details/10200207
Gerrit使用简介:
https://www.cnblogs.com/lexuele/p/5133601.html