Git push到gerrit时报错change xxx closed

Git push到gerrit时报错change xxx closed

报错日志:

To ssh://xxxx
 ! [remote rejected] HEAD -> refs/for/master (change http://xxxx/+/96707 closed)

可以看到这个提交已经closed了,而change-Id未更改。

即使用了已经合入的change-Id,在一次push 的时候远端判断此change-Id 已经使用,所以报错。

所以需要更新commit的change-Id。

有两种办法:

  1. 如果对应的commit就是第一个,直接

    git commit --amend
    

    然后删除change-Id一行:

     Change-Id: I1bd9517834af01ebb372be25de74444aadbe6fb3
    

    保存并退出编辑页面,git会自动生成新的change-Id。

  2. 如果对应的commit不是最新的第一个提交,则用git rebase解决,找到第几个提交报错(示例为第145个提交)

    git rebase -i HEAD~145
    

    然后结合rebase的工具提示:

    # Rebase 08d9cc6..7fce9cd onto 08d9cc6 (145 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
    # d, drop = remove commit
    #
    # 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.
    #
    # Note that empty commits are commented out
    

    将报错的commit前的pick,修改为r,即“使用commit,需要编辑commit信息”:

    pick 7b2251e xxxx-commit-message-a
    pick 5a9a39a xxxx-commit-message-b
    pick 13a6201 xxxx-commit-message-c
    r d0e0797 xxxx-commit-message-d
    

    同样删除change-Id一行,保存并退出编辑页面,也由git自动生成新的change-Id即可。

posted @   付时凡  阅读(2187)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示