读书人

gerrit 常用命令记要

发布时间: 2012-06-30 17:20:12 作者: rapoo

gerrit 常用命令记录

?

基本操作创建和销毁

分支列表:

$: git branch* master  prepub  product

创建分支:

$: git branch prepub

切换已有分支:

$: git checkout prepubSwitched to branch 'prepub'

创建并切换分支:

$: git checkout -b issue1234Switched to branch 'issue1234'

删除分支:

$: git branch -d issue1234Deleted branch issue1234 (was b904c07).
合并和冲突

合并前要先切回?要并入?的分支。

以下表示issue1234分支合并入master分支

$: git checkout master$: git merge issue1234Merge made by recursive. README |    1 + 1 files changed, 1 insertions(+), 0 deletions(-)

冲突的时候,git会报出哪些文件冲突,这时候需要手动解决完冲突方可提交。

$: git merge issue1234Auto-merging index.htmlCONFLICT (content): Merge conflict in index.htmlAutomatic merge failed; fix conflicts and then commit the result.

通过git status查看冲突文件。

$: git statusindex.html: needs merge# On branch master# Changed but not updated:#   (use "git add <file>..." to update what will be committed)#   (use "git checkout -- <file>..." to discard changes in working directory)##unmerged:   index.html#

打开index.html,git会在冲突位置做上标示。

<<<<<<< HEAD:index.html<div id="footer">contact : email.support@github.com</div>=======<div id="footer">  please contact us at support@github.com</div>>>>>>>> iss53:index.html

解决完冲突,这时候需要手动标识该冲突已经解决,类似svn的resolved

$: git add index.html$: git status# On branch master# Changed but not updated:#   (use "git add <file>..." to update what will be committed)#   (use "git checkout -- <file>..." to discard changes in working directory)##modified:   index.html#

这时候就可以提交了。

$: git commit -m "合并issue1234"[master e3ece67] 合并issue1234 1 files changed, 1 insertions(+), 0 deletions(-)
管理多个分支

前面提到,git非常推荐频繁使用分支,在大量分支的情况下,我们需要对分支做好管理(曾经一次上线,开了13个分支?= =

通过-v可以看到最后一次提交日志。

$: git branch -v* master          b904c07 把丘迟的产品搜改动合并一下  p4popt          8b93380 p4p加上refpid,开发给出来的配置是 P4P_refpid  prepub          a6cc66b P4P解析参数少一次替换,顺便解决\!失效的问题  product         301ae4e rankbar图片换成data uri

通过--merged--no-merged来查看分支是否已经合并完成。

$: git branch --merged* master  p4popt$: git branch --no-merged  prepub  product

未合并的分支,在删除时会提示分支未合并。

$: git branch -d productwarning: deleting branch 'product' that has been merged to         'refs/remotes/s/product', but it is not yet merged to HEAD.Deleted branch product (was 301ae4e).
分支管理流程

一般情况下,分支可以划分为长分支和短分支两种。

长分支

读书人网 >开源软件

热点推荐