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

相关推荐
六点半8885 小时前
【Git】远程操作 + 给命令配置别名 + 标签管理
git
虫师c8 小时前
GitOps实战:ArgoCD+Tekton打造云原生CI/CD流水线
git·ci/cd·云原生·kubernetes·argocd·tekton
间彧9 小时前
git远程仓库地址发生更改,如何通过命令进行修改
git
xxxandwww12 小时前
git仓库常用命令
git
yan8626592461 天前
git操作
git
六点半8881 天前
【Git】分⽀管理
git
小前端学徒1 天前
重新修改未提交到远程分支不是最后一次commit的内容
git
执键行天涯1 天前
idea中已经被git缓存追踪的文件,如何让git重新忽略
git·缓存·intellij-idea
hkhkhkhkh1231 天前
Git push 失败(remote unpack failed: Missing tree)解决方案
linux·git
拾贰_C1 天前
【anaconda】anaconda安装配置,git安装配置以及pytorch安装
人工智能·pytorch·git