Git push到gerrit时报错change xxx closed
报错日志:
To ssh://xxxx
! [remote rejected] HEAD -> refs/for/master (change http://xxxxm/+/96107 closed)
可以看到这个提交已经closed了,而change id未更改。
即使用了已经合入的change id,在一次push 的时候远端判断此个change id 已经使用,所以报错。
所以需要更新commit的change id。
有两种办法:
-
如果对应的commit就是第一个,直接
git commit --amend
然后删除changeId一行,保存并退出编辑页面,git会自动生成新的changId。
-
如果对应的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信息”,同样删除changeId一行,保存并退出编辑页面,由git自动生成新的changId即可。