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 @ 2023-11-13 14:48  付时凡  阅读(3183)  评论(0)    收藏  举报