Gerrit workflow

提交代码

每次提交代码前,先执行 git pull --rebase ,确保已经合并天上代码,解决冲突

git add

git commit -m

git push origin HEAD:refs/for/{BRANCH_NAME}

可考虑设置 alias 方式,参考下文

CR-2 情况处理(verify-1情况一样处理)

d794693 2015-11-12 (HEAD -> master) commit 7 [lvgx]

f1bbc51 2015-11-12 commit 6 [lvgx]

d813cd8 2015-11-12 commit 5 [lvgx]

cc00834 2015-11-12 commit 4 [lvgx]

ad1fdac 2015-11-12 commit 3 [lvgx]

12baec9 2015-11-12 commit 2 [lvgx](CR-2) 代码有问题的commit点

9c95373 2015-11-12 commit 1 [lvgx]

如果需要修改commit 2 提交点内容,重新提交;

1、rebase

复制代码
git rebase -i HEAD~6 or git rebase -i 9c95373(目标点前一个点)

pick 12baec9 commit 2

pick ad1fdac commit 3

pick cc00834 commit 4

pick d813cd8 commit 5

pick 2982c6d commit 6

pick 264870e commit 7

Rebase 9c95373...264870e onto 9c95373 (6 command(s))

Commands:

p, pick = use commit

r, reword = use commit, but edit the commit message

e, edit = use commit, but stop for amending

s, squash = use commit, but meld into previous commit

f, fixup = like "squash", but discard this commit's log message

x, exec = run command (the rest of the line) using shell

These lines can be re-ordered; they are executed from top to bottom.

If you remove a line here THAT COMMIT WILL BE LOST.

However, if you remove everything, the rebase will be aborted.

"~/Desktop/gerrit/test2/matchbox-app-android/.git/rebase-merge/git-rebase-todo" 24L, 747C

2、将commit2的pick修改为"edit"

pick 12baec9 commit 2 为 edit 12baec9 commit 2

保存退出

xz@xzdeMacBook-Pro:matchbox-app-android$ git rebase -i 9c95373

Stopped at 12baec9f5a1f3611ba071c59548f20ab3279dbb9... commit 2

You can amend the commit now, with

复制代码
        git commit --amend 

    Once you are satisfied with your changes, run

        git rebase --continue

3、修改代码,执行

git add .

git commit --amend

4、git rebase --continue

5、git review

Abandon 情况处理

commit一但出现abandon,这个changeid将不再允许commit

xz@xzdeMacBook-Pro:~/Desktop/gerrit/test3/matchbox-app-android$ git push riv

Counting objects: 3, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (3/3), done.

Writing objects: 100% (3/3), 337 bytes | 0 bytes/s, done.

Total 3 (delta 2), reused 0 (delta 0)

remote: Resolving deltas: 100% (2/2)

remote: Processing changes: refs: 1, done

To ssh://lvgx@192.168.14.217:29418/matchbox-app-android

! [remote rejected] HEAD -> refs/for/master (change http://192.168.14.217:8281/132 closed)

error: failed to push some refs to 'ssh://lvgx@192.168.14.217:29418/matchbox-app-android'

此时需要新建一个commit实现代码提交,执行reset操作

1、git reset

xz@xzdeMacBook-Pro:~/Desktop/gerrit/test3/matchbox-app-android$ git reset 1876441

Unstaged changes after reset:

M commit3

xz@xzdeMacBook-Pro:~/Desktop/gerrit/test3/matchbox-app-android$ git st

On branch master

Your branch is ahead of 'origin/master' by 13 commits.

(use "git push" to publish your local commits)

Changes not staged for commit:

(use "git add ..." to update what will be committed)

(use "git checkout -- ..." to discard changes in working directory)

modified: commit3

no changes added to commit (use "git add" and/or "git commit -a")

2、git commit

xz@xzdeMacBook-Pro:~/Desktop/gerrit/test3/matchbox-app-android$ git commit -am "commit52+"

master 3cb427e\] commit52+ 1 file changed, 1 insertion(+) 3、pull 建议每次review之前 运行 git pull --rebase git pull --rebase 4、git review 冲突情况处理 冲突情况出现,说明其他人做了相同文件的修改,且优先入库了; 先 commit 本地内容只本地仓库 执行 git pull --rebase 操作,合并天上内容 修改 rebase 过程中遇到的冲突问题 执行 git review 操作 别名设置 配置多branch情况建议配置config文件 cd ~ vim .gitconfig 添加 \[alias

review = !sh -c 'git push origin HEAD:refs/for/$1' -

review 分支使用

复制代码
git review branch-name 

reset 介绍

type Index WorkDir WD safe

soft NO NO YES

mixed YES NO YES

hard YES YES NO

--mixed reset HEAD and index

--soft reset only HEAD

--hard reset HEAD, index and working tree

相关推荐
爱喝矿泉水的猛男10 分钟前
git-子仓操作
git·submodule
中东大鹅44 分钟前
Git基础
大数据·git·elasticsearch
哈里谢顿5 小时前
git的一些操作
git
测试开发技术6 小时前
Git 中如何比较不同版本之间的差异?常用命令有哪些?
git·gitlab·github·面试题
中东大鹅6 小时前
Git仓库使用
git
我是阿呆同学6 小时前
Git--本地仓库的学习
git
求知摆渡11 小时前
Windows 下 Git Clone 报错:Filename too long 的解决方案
git
测试开发技术18 小时前
Git 中如何查看提交历史?常用命令有哪些?
git·gitlab·github·面试题
Rains042221 小时前
Git Revert 使用指南(基础用法)
git