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

相关推荐
弹简特2 小时前
【测试基础】11-软件测试之测试方案编写&测试报告编写&Git工具安装
git·功能测试
吴声子夜歌15 小时前
TypeScript——泛型
前端·git·typescript
春日见15 小时前
3三分彻底了解Git Graph极其应用
git
风.foxwho17 小时前
jenkins使用 ED25519密钥 拉取Git 代码 配置
git·servlet·jenkins
ruanCat18 小时前
前端工程化工具链从零配置:simple-git-hooks + lint-staged + commitlint
前端·git·代码规范
木子小喵19 小时前
Git的使用介绍!超通俗!
git
coderYYY19 小时前
git push报错Authentication failed for ‘xxx’也不会弹要求输入用户名密码的最终解决方法
前端·git·gitee·github
@PHARAOH20 小时前
WHAT - git worktree 开发的并发模型
大数据·git·elasticsearch
苦瓜小生1 天前
【Git】| 将拉下来的代码上传到自己的 Gitee 仓库(手把手教学)
git·gitee
WKP94181 天前
git的merge和rebase操作
git