如何在gerrit中修改已提交的change

在gerrit审核中,经常会遇到开发人员提交的代码审核不通过的情况。

那么开发人员这时有两个选择:1)按照要求修改代码,然后重新提交一次代码。2)修改原来的Change。

第一种方法会产生多次commit,而这些commit实际上是没有太多意义的,所以不推荐使用。

所以推荐第二种方法。下面讲解如何做:

安装 commit-msg hook

安装gerrit的commit-msg hook的目的是为了能够在每次提交的时候在你的本地产生一个Change-Id,这个Change-Id是将gerrit的Change和你的commit联系起来的纽带。

1
2
3
# 到项目的根目录下执行
curl -Lo .git/hooks/commit-msg http://your-gerrit-server/gerrit/tools/hooks/commit-msg
chmod u+x .git/hooks/commit-msg

这样的话,你每次提交的时候,这个hook都会在commit message的后面添加一行Change-Id:

1
2
3
4
5
6
7
8
9
10
11
12
  $ git log -1
  commit 29a6bb1a059aef021ac39d342499191278518d1d
  Author: A. U. Thor <author@example.com>
  Date: Thu Aug 20 12:46:50 2009 -0700

      Improve foo widget by attaching a bar.

      We want a bar, because it improves the foo by providing more
      wizbangery to the dowhatimeanery.

      Bug: #42
      Change-Id: Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b

修改已经提交至gerrit的commit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ git checkout 有问题的commit
$ <修改>
$ git commit --amend
$ git push origin HEAD:refs/for/master
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 546 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Processing changes: updated: 1, done
remote:
remote: Updated Changes:
remote:   http://gerrithost:8080/68
remote:
To ssh://gerrithost:29418/RecipeBook.git
 * [new branch]      HEAD -> refs/for/master

注意到上面的Updated Changes字样了吗?这说明我们是更新了gerrit上的Change,而不是一般情况下的New Changes。

然后你到gerrit上查看自己的Change,是不是有变化了?

windows下怎么弄?

commit-msg hook在windows下可能无法起作用,但我们依然有办法解决这问题。

我们还是按照前面讲的步骤来:

1
2
3
$ git checkout 有问题的commit
$ <修改>
$ git commit --amend

注意,这个时候你需要手工添加Change-Id了,到gerrit上找到自己的Change的Change-Id:

上图的最后一样就是Change-Id,然后手工添加到commit注释的最后一行上:

1
Change-Id: I347f61e90f259c78fcaaa8367b804941005a9b2b

然后

1
2
3
4
5
6
7
8
9
10
11
12
13
$ git push origin HEAD:refs/for/master
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 546 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Processing changes: updated: 1, done
remote:
remote: Updated Changes:
remote:   http://gerrithost:8080/68
remote:
To ssh://gerrithost:29418/RecipeBook.git
 * [new branch]      HEAD -> refs/for/master
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
YOLO高分设计资源源码,详情请查看资源内容使用说明 YOLO高分设计资源源码,详情请查看资源内容使用说明 YOLO高分设计资源源码,详情请查看资源内容使用说明 YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明YOLO高分设计资源源码,详情请查看资源内容使用说明

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值