git 提交消息中的 Change-Id 丢失时的 Gerrit 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8845658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gerrit error when Change-Id in commit messages are missing
提问by Pan Ruochen
I set up a branch in the remote repository and made some commits on that branch. Now I want to merge the remote branch to the remote master.
我在远程存储库中设置了一个分支并在该分支上进行了一些提交。现在我想将远程分支合并到远程主节点。
Basically follows are my operations:
基本上以下是我的操作:
- checkout branch
- checkout master
- merge branch and fix merging errors
- commit
- push origin HEAD:refs/for/master
- 结账分行
- 收银员
- 合并分支并修复合并错误
- 犯罪
- push origin HEAD:refs/for/master
But get error messages on the 5th step:
但是在第 5 步得到错误信息:
remote: Resolving deltas: 0% (0/12)
remote: ERROR: missing Change-Id in commit message
...
remote: Change-Id: I55862204ef71f69bc88c79fe2259f7cb8365699a
To ssh://[email protected]:29418/hello_git
! [remote rejected] HEAD -> refs/for/master (missing Change-Id in commit message)
回答by Rafa? Rawicki
Check if your commits have Change-Id: ...
in their descriptions. Every commit should have them.
检查您的提交是否Change-Id: ...
在其描述中。每个提交都应该有它们。
If no, use git rebase -i
to reword the commit messages and add proper Change-Ids (usually this is a SHA1 of the first version of the reviewed commit).
如果不是,则用于git rebase -i
改写提交消息并添加适当的 Change-Id(通常这是已提交的第一个版本的 SHA1)。
For the future, you should install commit hook, which automatically adds the required Change-Id.
将来,您应该安装 commit hook,它会自动添加所需的 Change-Id。
Execute scp -p -P 29418 username@your_gerrit_address:hooks/commit-msg .git/hooks/
in the repository directory
or download them from
http://your_gerrit_address/tools/hooks/commit-msg
and copy to .git/hooks
scp -p -P 29418 username@your_gerrit_address:hooks/commit-msg .git/hooks/
在存储库目录中执行或从中下载
http://your_gerrit_address/tools/hooks/commit-msg
并复制到 .git/hooks
回答by vailaya shreesha
Try this:
尝试这个:
git commit --amend
Then copy and paste the Change-Id: I55862204ef71f69bc88c79fe2259f7cb8365699a
at the end of the file.
然后复制并粘贴Change-Id: I55862204ef71f69bc88c79fe2259f7cb8365699a
到文件末尾。
Save it and push it again!
保存并再次推送!
回答by Matt Cowell
If you need to add Change-Id to multiple commits, you can download the hook from your Gerrit server and run these commands to add the Change-Ids to all commits that need them at once. The example below fixes all commits on your current branch that have not yet been pushed to the upstream branch.
如果您需要将 Change-Id 添加到多个提交中,您可以从 Gerrit 服务器下载钩子并运行这些命令以将 Change-Id 一次添加到所有需要它们的提交中。下面的示例修复了当前分支上尚未推送到上游分支的所有提交。
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
回答by manojlds
It is because Gerrit is configured to require Change-Id in the commit messages.
这是因为 Gerrit 被配置为在提交消息中需要 Change-Id。
http://gerrit.googlecode.com/svn-history/r6114/documentation/2.1.7/error-missing-changeid.html
http://gerrit.googlecode.com/svn-history/r6114/documentation/2.1.7/error-missing-changeid.html
You have to change the messages of every commit that you are pushing to include the change id ( using git filter-branch
) and only then push.
您必须更改您推送的每个提交的消息以包含更改 ID( using git filter-branch
),然后才推送。
回答by Ivan Vu?ica
You might be an admin doing a one-off push directly into refs/changes/<change_number>
.
您可能是一名管理员,将一次性推送到refs/changes/<change_number>
.
For example, once a commit without Change-Id landed into Subversion, you pull it out of Subversion using git-svn, and you'd like to archive it as a Gerrit patchset into a Gerrit change.
例如,一旦没有 Change-Id 的提交进入 Subversion,您就可以使用 git-svn 将其从 Subversion 中提取出来,并且您希望将其作为 Gerrit 补丁集存档到 Gerrit 更改中。
If so, you can go to project settings page (http://[installation-path]/#/admin/projects/[project-id]) and temporarily change "Require Change-Id in commit message" value to False.
如果是这样,您可以转到项目设置页面(http://[installation-path]/#/admin/projects/[project-id])并临时将“提交消息中的要求更改 ID”值更改为 False。
Don't forget to afterwards change it back to Inherit or True!
之后不要忘记将其改回 Inherit 或 True!
回答by Mahi
Check your git repo before committing
在提交之前检查你的 git repo
gitrepo/.git/hooks/commit-msg
if this file is not present in that location then you will get this error "missing Change-Id in commit message" .
如果该文件不存在于该位置,那么您将收到此错误“提交消息中缺少更改 ID”。
To solve this just copy paste the commit hook in .git folder.
要解决这个问题,只需将提交钩子复制粘贴到 .git 文件夹中。
回答by Kashan
You need to follow below 2 steps instructions:
您需要按照以下 2 步说明进行操作:
[Issue] remote: Hint: To automatically insert Change-Id, install the hook:
[问题] 远程:提示:要自动插入 Change-Id,请安装钩子:
1) gitdir=$(git rev-parse --git-dir);
1) gitdir=$(git rev-parse --git-dir);
2) scp -p -P 29418 <username>@gerrit.xyz.se:hooks/commit-msg ${gitdir}/hooks/
2) scp -p -P 29418 <username>@gerrit.xyz.se:hooks/commit-msg ${gitdir}/hooks/
normally $gitdir = ".git". You need to update the username and the Gerrit link.
通常 $gitdir = ".git"。您需要更新用户名和 Gerrit 链接。
回答by Ravi Yadav
1) gitdir=$(git rev-parse --git-dir);
1) gitdir=$(git rev-parse --git-dir);
2) scp -p -P 29418 <username>@gerrit.xyz.se:hooks/commit-msg ${gitdir}/hooks/
a) I don't know how to execute step 1 in windows so skipped it and used hardcoded path in step 2 scp -p -P 29418 <username>@gerrit.xyz.se:hooks/commit-msg .git/hooks/
a) 我不知道如何在 windows 中执行第 1 步,所以跳过它并使用硬编码路径 step 2 scp -p -P 29418 <username>@gerrit.xyz.se:hooks/commit-msg .git/hooks/
b) In case you get below error, manually create "hooks" directory in .git folder
b) 如果出现以下错误,请在 .git 文件夹中手动创建“hooks”目录
protocol error: expected control record
c) if you have submodule let's say "XX" then you need to repeat step 2 there as well and this time replace ${gitdir} with that submodules path
c) 如果你有子模块让我们说“XX”那么你也需要在那里重复第 2 步,这次用那个子模块路径替换 ${gitdir}
d) In case scp is not recognized by windows give full path of scp
d) 如果 Windows 无法识别 scp,请提供 scp 的完整路径
"C:\Program Files\Git\usr\bin\scp.exe"
e) .git folder is present in your project repo and it's hidden folder
e) .git 文件夹存在于您的项目仓库中,它是隐藏文件夹
回答by schin chan
under my .git/hooks folder, some sample files were missing. like commit-msg,post-commit.sample,post-update.sample...adding these files resolved my change id missing issue.
在我的 .git/hooks 文件夹下,缺少一些示例文件。像 commit-msg,post-commit.sample,post-update.sample...添加这些文件解决了我的更改 ID 丢失问题。
回答by kagb
I got this error message too.
我也收到了这个错误信息。
and what makes me think it is useful to give an answer here is that the answer from @Rafa? Rawicki is a good solution in some cases but not for all circumstances. example that i met:
是什么让我认为在这里给出答案有用的是@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"
solution:
解决方案:
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