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

相关推荐
Aurora_th13 小时前
浙江海洋大学 资料共享 期末考试卷、课程资料等
git·github
奶茶树16 小时前
【C++】13. C++11新特性【上】
c语言·开发语言·c++·git·github
夏至春来-美美1 天前
git clone报错
git
拂拉氏1 天前
【Linux】 开发工具(Makefile、git、cgdb)解析与对于操作系统的基础认识
linux·git·操作系统·makefile·cgdb
番茄不是西红柿kk2 天前
deepseek-harness跨平台桌面端二开项目(附git仓库地址+安装包)
git·agent·codex·deepseek·deepseekharness
leoZ2312 天前
10-Git 仓库蒸馏术:从代码仓库到 OpenClaw 虚拟人-蒸馏工具链
大数据·git·深度学习·神经网络·目标检测·elasticsearch·lstm
fpcc2 天前
工具使用—git diff命令分析说明
git·工具
console.log('npc')2 天前
Git 删除指定提交记录操作指南
git
随风丶飘2 天前
[特殊字符] 告别“update“和“fix bug“——Smart Git Commit LLM 让 AI 帮你写专业的 Git 提交信息
人工智能·git·bug
yanlaifan2 天前
git clone时候指定换行符
git