缺少提交消息中的Change-Id时出现Gerrit错误

时间:2012-01-13 03:47:17

标签: git merge branch master gerrit

我在远程存储库中设置了一个分支,并在该分支上进行了一些提交。 现在我想将远程分支合并到远程主服务器。

以下是我的操作:

  1. 结帐分行
  2. 结帐大师
  3. 合并分支并修复合并错误
  4. 提交
  5. 推送起源HEAD:refs / for / master
  6. 但是在第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)
    

12 个答案:

答案 0 :(得分:72)

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

如果不是,请使用git rebase -i重新提交提交消息并添加正确的Change-Ids(通常这是已审核提交的第一个版本的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

答案 1 :(得分:24)

试试这个:

git commit --amend

然后复制并粘贴文件末尾的Change-Id: I55862204ef71f69bc88c79fe2259f7cb8365699a

保存并再次推送!

答案 2 :(得分:7)

如果需要将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

答案 3 :(得分:4)

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

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

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

答案 4 :(得分:2)

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

例如,一旦没有Change-Id的提交登陆到Subversion,你就可以使用git-svn将它从Subversion中删除,并且你想将它作为Gerrit补丁集归档到Gerrit更改中。

如果是这样,您可以转到项目设置页面(http://[installation-path]/#/admin/projects/[project-id])并临时更改提交消息中的&#34; Require Change-Id&#34;值为False。

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

答案 5 :(得分:1)

在提交之前检查你的git repo

protocol SomeProtocol {
    typealias SomeType = Int // used typealias-assignment

    func someFunc(someVar: SomeType)
}

class SomeClass: SomeProtocol {
    func someFunc(someVar: SomeType) {
        print(someVar)
    }
}

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

要解决这个问题,只需复制粘贴.git文件夹中的提交挂钩。

答案 6 :(得分:1)

您需要按照以下2个步骤说明操作:

[问题] 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 =&#34; .git&#34;。您需要更新用户名和Gerrit链接。

答案 7 :(得分:1)

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 <username>@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文件夹存在于您的项目存储库中,并且是隐藏文件夹

答案 8 :(得分:0)

我也收到了此错误消息。

是什么让我觉得在这里给出答案是有用的,@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

答案 9 :(得分:0)

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

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

答案 10 :(得分:0)

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

答案 11 :(得分:-1)

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

  

请输入您的更改提交消息。以'#'开头的行将被忽略,空消息将中止提交。

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

我遇到了同样的错误,但我已经拥有了commit-msg并完成了rebase和所有事情。但是非常愚蠢的错误:D