欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 游戏 > 推送到Gerrit时报错,缺少Change-Id

推送到Gerrit时报错,缺少Change-Id

2025/5/12 9:58:39 来源:https://blog.csdn.net/weixin_45764765/article/details/147829681  浏览:    关键词:推送到Gerrit时报错,缺少Change-Id

背景:Gerrit 是一个基于 Git 的 代码审查工具,可以更好地集成AI代码审核。

1、问题描述

代码提交,推送到Gerrit时报错

remote: Hint: to automatically insert a Change-Id, install the hook:        
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 12345 yonghai.xie@172.12.12.123:hooks/commit-msg ${gitdir}/hooks/        
remote: (for OpenSSH >= 9.0 you need to add the flag '-O' to the scp command)        
remote: or, for http(s):        
remote:   f="$(git rev-parse --git-dir)/hooks/commit-msg"; curl -o "$f" http://172.12.12.123:8080/tools/hooks/commit-msg ; chmod +x "$f"        
remote: and then amend the commit:        
remote:   git commit --amend --no-edit        
remote: Finally, push your changes again        
remote: 
error: failed to push some refs to 'http://172.12.12.123:8080/spring6'

2、问题分析

提交的 Git commit 缺少必要的 Change-Id 标识,导致远程仓库拒绝推送。

远程仓库规则限制:目标仓库使用了 Gerrit 或类似代码审查系统,要求每个提交必须包含 Change-Id。
未安装提交钩子:本地 Git 没有安装 Gerrit 提供的 commit-msg 钩子脚本,因此无法自动生成 Change-Id。
提交被拒绝:由于缺少 Change-Id,Gerrit 拒绝了此次 push 请求。

3、解决

依次执行以下命令

 在对应项目的根目录文件夹下打开【Git Bash】

1.下载并安装 commit-msg 钩子

# 获取 commit-msg 钩子脚本

f="$(git rev-parse --git-dir)/hooks/commit-msg"

#172.12.12.123(自己具体的仓库地址) 

curl -o "$f" http://172.12.12.123:8080/tools/hooks/commit-msg

 # 添加可执行权限

chmod +x "$f"

2.修正最近一次提交以添加 Change-Id

# 修正最后一次提交,不修改提交信息内容

git commit --amend --no-edit

3.重新推送代码

# dev20250509(自己具体的分支)

git push origin HEAD:refs/for/dev20250509

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com