【问题标题】:Git Push failed due to Change-Id由于 Change-Id,Git Push 失败
【发布时间】:2020-04-15 15:17:56
【问题描述】:

对我来说,当我尝试推送代码时,Git 每次都会产生错误。使用以下命令

git push origin HEAD:refs/for/master

所以对于临时修复我必须使用下面的命令

 git commit --amend

然后手动将Change-Id添加到另一个Stackoverflow question之后,这样就可以推送代码了。

但是,如果我下次尝试推送任何其他代码,它将失败并出现同样的错误(请看下面)

Counting objects: 63, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (39/39), done.
Writing objects: 100% (63/63), 5.94 KiB | 0 bytes/s, done.
Total 63 (delta 22), reused 28 (delta 4)
remote: Resolving deltas: 100% (22/22)
remote: Processing changes: refs: 1, done
remote: ERROR: [2a1ab5e] missing Change-Id in commit message footer
remote:
remote: Hint: To automatically insert Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 subodhjoshi@gerrit.ext.net.google.com:hooks/commit-msg ${gitdir}/hooks/
remote: And then amend the commit:
remote:   git commit --amend
remote:
To ssh://gerrit.ext.net.google.com:29418/projectname/framework
 ! [remote rejected]   HEAD -> refs/for/master ([2a1ab5e] missing Change-Id in commit message footer)
error: failed to push some refs to 'ssh://gerrit.ext.net.google.com:29418/projectname/framework'

所以我尝试添加这样的钩子

$ scp -p -P 29418 subodhjoshi@gerrit.ext.net.google.com:hooks/commit-msg  C:/GIT_Code_Base/unified-inventory/framework/framework/.git/hooks/
commit-msg                                    100% 4780    23.7KB/s   00:00

再次尝试推送,但最终出现同样的错误。

我的问题是,为什么每次我都必须在提交之前添加 change-Id ?此问题的永久修复方法是什么?

【问题讨论】:

  • 只是好奇,HEAD:refs/for/master是什么,我通常只是git push origin master
  • @LoiNguyenHuynh 我们正在使用这个HEAD:refs/for/master
  • @LoiNguyenHuynh 这些是 Gerrit 的网址。
  • @LoiNguyenHuynh 我们将 Gerrit 与 Git 一起使用,因此任何代码推送都需要批准才能合并。所以实际上我们正在使用图像。
  • 您需要来自 Gerrit 的 commit-msg。设置完成后,执行 rebase 以将 Change-Id 添加到现有提交中。

标签: git gerrit


【解决方案1】:

Gerrit 消息是不言自明的,只需执行以下操作:

1) 进入本地仓库目录:

cd LOCAL-REPO-DIR

2) 安装 commit-msg 钩子:

gitdir=$(git rev-parse --git-dir); scp -p -P 29418 subodhjoshi@gerrit.ext.net.google.com:hooks/commit-msg ${gitdir}/hooks/

3) 修复你当前的提交:

git commit --amend

注意 1:在第 3 步中,您不需要更改提交中的任何内容,只需运行“git commit --amend”命令,保存提交消息并退出。 Change-Id 将由 commit-msg 挂钩自动添加。执行“git log”检查是否正确添加了Change-Id。

注意 2:从现在开始,每次创建提交时,commit-msg 挂钩都会自动添加 Change-Id。

【讨论】:

    猜你喜欢
    • 2014-07-20
    • 2021-03-15
    • 2013-03-21
    • 2014-04-30
    • 2011-04-26
    • 1970-01-01
    • 2012-11-18
    • 2023-03-04
    • 2015-07-17
    相关资源
    最近更新 更多