【问题标题】:Gerrit error when Change-Id in commit messages are missing缺少提交消息中的 Change-Id 时出现 Gerrit 错误
【发布时间】:2012-02-09 08:47:44
【问题描述】:

我在远程存储库中建立了一个分支,并在该分支上进行了一些提交。 现在我想将远程分支合并到远程master。

基本上以下是我的操作:

  1. 结帐分行
  2. 结帐大师
  3. 合并分支并修复合并错误
  4. 提交
  5. 推源 HEAD:refs/for/master

但在第 5 步得到错误消息:

remote: Resolving deltas:   0% (0/12)

remote: ERROR: missing Change-Id in commit message
...

remote: Change-Id: I55862204ef71f69bc88c79fe2259f7cb8365699a

To ssh://prc@test.gerrit.xxx.com:29418/hello_git
 ! [remote rejected] HEAD -> refs/for/master (missing Change-Id in commit message)

【问题讨论】:

  • 就像 git promot:gitdir=$(git rev-parse --git-dir); scp -p -P 29418 user@host:hooks/commit-msg ${gitdir}/hooks/ 然后git commit --amend --no-edit
  • @Galley,我认为这是针对上面发布的问题的最简单的解决方案。我想根据终端上 git 的建议与 SO 确认。它对我有用。

标签: git merge branch master gerrit


【解决方案1】:

检查您的提交是否在其描述中包含Change-Id: ...。每个提交都应该有它们。

如果不是,请使用 git rebase -i 改写提交消息并添加正确的 Change-Id(通常这是已审核提交的第一个版本的 SHA1)。

以后你应该安装commit hook,它会自动添加所需的Change-Id。

在仓库目录中执行scp -p -P 29418 username@your_gerrit_address:hooks/commit-msg .git/hooks/ 或从 http://your_gerrit_address/tools/hooks/commit-msg 并复制到 .git/hooks

【讨论】:

  • 我发现如果您添加例如,Gerrit 可能会错过 Change-Id:在它下面有一个“冲突:”行。所以请确保它在提交的最后一行。
  • @qneill 听起来像是一个错误,你能把它报告给 Gerrit 开发者吗?
  • @RafałRawicki:按照设计,Gerrit(实际上是 JGit)只识别提交消息最​​后一段中的“Key: Value”页脚行。 Gerrit 无法帮助添加 Git 添加的“冲突:”行。如果消息末尾和“Change-Id:”行下方有“Conflict:”行,则更改 commit-msg 挂钩以发出警告或退出可能是可行的。
  • 我使用git log找到了changedId,但仍然出现同样的错误。
  • your_gerrit_address/tools/hooks/commit-msg 下载并复制到 .git/hooks 对我有用。感谢 Rafal 的精彩回答。
【解决方案2】:

试试这个:

git commit --amend

然后将Change-Id: I55862204ef71f69bc88c79fe2259f7cb8365699a复制粘贴到文件末尾。

保存并再次推送!

【讨论】:

  • 这是一个快速修复,但提供了“正确”答案@Rafał Rawicki
  • 像魅力一样工作。只需在提交注释下添加 ChangeId: XXXXXXX 即可。这比其他解决方案更容易,必须投票作为答案。
【解决方案3】:

如果您需要将 Change-Id 添加到多个提交,您可以从 Gerrit 服务器下载钩子并运行这些命令以将 Change-Ids 添加到一次需要它们的所有提交中。下面的示例修复了当前分支上尚未推送到上游分支的所有提交。

tmp=$(mktemp)
hook=$(readlink -f $(git rev-parse --git-dir))/hooks/commit-msg
git filter-branch -f --msg-filter "cat > $tmp; \"$hook\" $tmp; cat $tmp" @{u}..HEAD

【讨论】:

  • 你能解释一下如何运行它吗?
  • 将此内容复制到文件并作为 shell 脚本运行。
  • 这对我不起作用,它说我没有配置上游。你能解释一下你在这里做什么吗?另外,readlink -f 不能在 mac 上运行。
  • @{u} 是一种快速引用您正在跟踪并应该推送到的上游分支的方法。如果由于某种原因没有跟踪上游分支,则可以使用完整的 ref 名称代替 @{u},例如 origin/foo 。您也可以使用 Git 提供的命令设置上游,例如 git branch -u origin/foo@{u}..HEAD 只是指定要重写的提交范围,因此您可以使用任何您喜欢的格式来指定范围。
  • 对我来说,上面的脚本返回Found nothing to rewrite。在我的情况下,如何将其更改为将Change-Id 添加到每个提交消息中:stackoverflow.com/q/52321292/630169。谢谢!
【解决方案4】:

这是因为 Gerrit 被配置为在提交消息中需要 Change-Id。

http://gerrit.googlecode.com/svn-history/r6114/documentation/2.1.7/error-missing-changeid.html

您必须更改要推送的每个提交的消息以包含更改 ID(使用 git filter-branch),然后才推送。

【讨论】:

  • 我运行 git commit --amend 来修复提交日志消息:以下是当前日志消息:commit 8152da05ce0235cb779620410474731868664296 作者:PRC 日期:1 月 12 日星期四 17:24: 33 2012 +0800 Merge my branch to master Change-Id: I70aee922f6310e4766eb15694deb2fb3579ed042 但是我仍然无法将分支推送到master,同样的错误。
【解决方案5】:

您可能是一名管理员,直接向refs/changes/<change_number> 进行一次性推送。

例如,一旦没有 Change-Id 的提交进入 Subversion,您可以使用 git-svn 将其从 Subversion 中拉出,并且您希望将其作为 Gerrit 补丁集存档到 Gerrit 更改中。

如果是这样,您可以转到项目设置页面 (http://[installation-path]/#/admin/projects/[project-id]) 并将“提交消息中需要更改 ID”值临时更改为 False。

不要忘记之后将其改回 Inherit 或 True!

【讨论】:

    【解决方案6】:

    在提交之前检查你的 git 仓库

    gitrepo/.git/hooks/commit-msg
    

    如果该位置不存在此文件,则您将收到此错误“提交消息中缺少 Change-Id”。

    要解决这个问题,只需将提交钩子复制粘贴到 .git 文件夹中即可。

    【讨论】:

      【解决方案7】:

      您需要按照以下两步说明进行操作:

      [Issue] remote:提示:要自动插入 Change-Id,请安装 hook:

      1)gitdir=$(git rev-parse --git-dir);

      2) scp -p -P 29418 <username>@gerrit.xyz.se:hooks/commit-msg ${gitdir}/hooks/

      通常 $gitdir = ".git"。您需要更新用户名和 Gerrit 链接。

      【讨论】:

        【解决方案8】:

        1) gitdir=$(git rev-parse --git-dir);

        2) scp -p -P 29418 <username>@gerrit.xyz.se:hooks/commit-msg ${gitdir}/hooks/
        

        a) 我不知道如何在 windows 中执行第 1 步,所以跳过它并使用step 2 scp -p -P 29418 &lt;username&gt;@gerrit.xyz.se:hooks/commit-msg .git/hooks/ 中的硬编码路径

        b) 如果遇到以下错误,请在 .git 文件夹中手动创建“hooks”目录

        protocol error: expected control record
        

        c) 如果你有子模块,比如说“XX”,那么你也需要在那里重复步骤 2,这次用那个子模块路径替换 ${gitdir}

        d) 如果 Windows 无法识别 scp,请给出 scp 的完整路径

        "C:\Program Files\Git\usr\bin\scp.exe"
        

        e) .git 文件夹存在于您的项目仓库中,它是隐藏文件夹

        【讨论】:

          【解决方案9】:

          在我的 .git/hooks 文件夹下,一些示例文件丢失了。像 commit-msg,post-commit.sample,post-update.sample...添加这些文件解决了我的更改 ID 丢失问题。

          【讨论】:

            【解决方案10】:

            默认情况下,如果没有提供 Change-Id,Gerrit 将阻止推送审查。 Change-Id 被添加到客户端提交消息的页脚。您必须在开始时下载并设置 commit-msg 脚本。您可以在 Gerrits 文档中找到更多信息。

            git clone ssh://gerrithost:29418/RecipeBook.git RecipeBook
            scp -p -P 29418 gerrithost:hooks/commit-msg RecipeBook/.git/hooks/
            chmod u+x .git/hooks/commit-msg
            

            【讨论】:

              【解决方案11】:

              我也收到此错误消息。

              让我认为在这里给出答案很有用的是,@Rafał Rawicki 的答案在某些情况下是一个很好的解决方案,但并非适用于所有情况。 我遇到的例子:

              1.run "git log" we can get the HEAD commit change-id
              
              2.we also can get a 'HEAD' commit change-id on Gerrit website.
              
              3.they are different ,which makes us can not push successfully and get the "missing change-id error"
              

              解决方案:

              0.'git add .'
              
              1.save your HEAD commit change-id got from 'git log',it will be used later.
              
              2.copy the HEAD commit change-id from Gerrit website.
              
              3.'git reset HEAD'
              
              4.'git commit --amend' and copy the change-id from **Gerrit website** to the commit message in the last paragraph(replace previous change-id)
              
              5.'git push *' you can push successfully now but can not find the HEAD commit from **git log** on Gerrit website too
              
              6.'git reset HEAD'
              
              7.'git commit --amend' and copy the change-id from **git log**(we saved in step 1) to the commit message in the last paragraph(replace previous change-id)
              
              8.'git push *' you can find the HEAD commit from **git log** on Gerrit website,they have the same change-id
              
              9.done
              

              【讨论】:

                【解决方案12】:

                我们今天早上通过重新克隆存储库并重新应用更改解决了这个问题。这是将本地副本与 Gerrit 重新同步的最简单方法。与往常一样,我们首先创建了备份。

                尽管还有许多其他极其复杂的解决方案,但采用简单的方法来避免使事情变得更糟通常是有利的。

                【讨论】:

                  【解决方案13】:

                  如果您有此限制,也会发生这种情况:

                  请输入您的更改的提交消息。以“#”开头的行将被忽略,并且一条空消息中止提交。

                  你确实喜欢我:写一个以“#”开头的提交消息.....

                  我遇到了同样的错误,但我已经有了commit-msg 并做了rebase 和所有操作。非常愚蠢的错误:D

                  【讨论】:

                  • 问题没有提到这个错误信息,这个答案并没有真正回答问题。
                  猜你喜欢
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2021-06-28
                  • 2017-05-05
                  • 1970-01-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多