git操作手册
用gerrit管理项目git操作手册
安装git
安装过程略
配置用户名和邮箱
打开 git bash
git config –list 查看配置
git config –global user.name “John Doe”
git config –global user.email [email protected]
生成SSH Public Key
如果不知道怎么生成 点击我
配置SSH Public Key
用自己的账号登录gerrit系统,点击settings —>SSH Public Keys—>Add key
然后将生成的ssh public key(id_rsa.pub文件里面的内容) copy进去保存即可
克隆项目
找到项目的clone地址,如下图所示:
打开git bash , git clone ssh://[email protected]:29418/huanle 回车即可
注意,这一步如果出现下面的错误,在终端输入export GIT_SSH_COMMAND=’ssh -o KexAlgorithms=+diffie-hellman-group1-sha1’ 或者打开.bashrc文件,在终端输入:$ vim ~/.bashrc ,然后向.bashrc文件写入:export GIT_SSH_COMMAND=’ssh -o KexAlgorithms=+diffie-hellman-group1-sha1’
点击
Unable to negotiate with 10.103.7.98: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists
$export GIT_SSH_COMMAND='ssh -o KexAlgorithms=+diffie-hellman-group1-sha1'
把项目clone下来之后,注意copy一个叫commit-msg文件到项目的.git/hooks目录下,
如果不进行这一步,后面提交代码的时候不会生成change-id,提交代码会失败。
commit-msg文件可以在http://10.103.7.98:9000/tools/hooks/commit-msg下载
提交代码
提交代码到gerrit服务器上。
git push origin HEAD:refs/for/master
更新代码
git pull
git pull –rebase
git pull origin master
创建和切换分支
git branch -a 查看所有分支
git branch 查看本地分支
git checkout 分支名 切换分支名
git branch -D 分支名 删除分支
git branch 分支名 创建新分支
git checkout -b 分支名 创建并切换到新分支
拉取远程分支并创建本地分支
使用如下git命令查看所有远程分支:
git branch -r
1
二、拉取远程分支并创建本地分支
方法一
使用如下命令:
git checkout -b 本地分支名x origin/远程分支名x
使用该方式会在本地新建分支x,并自动切换到该本地分支x。
方式二
使用如下命令:
git fetch origin 远程分支名x:本地分支名x
使用该方式会在本地新建分支x,但是不会自动切换到该本地分支x,需要手动checkout。
常用命令
git log
git add file.text
git add .
git reset –soft commitid
git commit
git commit -m ‘提交信息’
git commit –amend
写得不好,请点击
centos6.5 安装git http://blog.csdn.net/mimica247706624/article/details/47317911