From b1bd3dc5e5beb5b71fc50be6804252a6561509d6 Mon Sep 17 00:00:00 2001 From: admin <263303411@qq.com> Date: Fri, 19 Dec 2025 15:44:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E5=AE=89=E8=A3=85commit-m?= =?UTF-8?q?sg=E9=92=A9=E5=AD=90=E6=9D=A5=E8=87=AA=E5=8A=A8=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90.-.md | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 %E5%AE%89%E8%A3%85commit-msg%E9%92%A9%E5%AD%90%E6%9D%A5%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90.-.md diff --git a/%E5%AE%89%E8%A3%85commit-msg%E9%92%A9%E5%AD%90%E6%9D%A5%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90.-.md b/%E5%AE%89%E8%A3%85commit-msg%E9%92%A9%E5%AD%90%E6%9D%A5%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90.-.md new file mode 100644 index 0000000..b55fcae --- /dev/null +++ b/%E5%AE%89%E8%A3%85commit-msg%E9%92%A9%E5%AD%90%E6%9D%A5%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90.-.md @@ -0,0 +1,140 @@ +这是Gerrit的另一个常见错误,缺少Change-Id。Gerrit要求每个提交都有一个唯一的Change-Id。需要安装commit-msg钩子来自动生成。 + +## 解决方案: + +### 1. 安装Gerrit的commit-msg钩子(推荐方法) + +```bash +# 进入你的Git仓库目录 +cd /e/rjb/zhini_im_android + +# 下载commit-msg钩子(使用SSH方式) +gitdir=$(git rev-parse --git-dir) +scp -p -P 29418 rw0067680@101.43.95.130:hooks/commit-msg "${gitdir}/hooks/" + +# 如果上面的命令失败(OpenSSH >= 9.0),尝试: +scp -p -O -P 29418 rw0067680@101.43.95.130:hooks/commit-msg "${gitdir}/hooks/" + +# 或者使用HTTP方式(如果SSH不行) +curl -o ".git/hooks/commit-msg" http://101.43.95.130:8080/tools/hooks/commit-msg +chmod +x ".git/hooks/commit-msg" +``` + +### 2. 为当前提交添加Change-Id + +```bash +# 使用commit-msg钩子重新生成提交信息 +git commit --amend --no-edit + +# 查看提交信息,确认Change-Id已添加 +git log --oneline -1 +``` + +### 3. 重新推送 + +```bash +git push origin HEAD:refs/for/hotfix-crash +``` + +## 完整的解决流程: + +### 步骤1:安装钩子 +```bash +# 方法1:使用scp(如果OpenSSH版本<9.0) +scp -p -P 29418 rw0067680@101.43.95.130:hooks/commit-msg .git/hooks/ + +# 方法2:使用scp(OpenSSH>=9.0) +scp -p -O -P 29418 rw0067680@101.43.95.130:hooks/commit-msg .git/hooks/ + +# 方法3:使用curl(最简单) +curl -o ".git/hooks/commit-msg" http://101.43.95.130:8080/tools/hooks/commit-msg +chmod +x ".git/hooks/commit-msg" +``` + +### 步骤2:验证钩子安装成功 +```bash +# 检查钩子文件是否存在 +ls -la .git/hooks/commit-msg + +# 检查文件权限 +file .git/hooks/commit-msg +``` + +### 步骤3:修正提交 +```bash +# 重新提交(会自动添加Change-Id) +git commit --amend --no-edit + +# 查看提交信息,应该能看到Change-Id +git log -1 --pretty=full +``` + +### 步骤4:重新推送 +```bash +git push origin HEAD:refs/for/hotfix-crash +``` + +## 如果遇到权限问题: + +```bash +# 确保钩子有执行权限 +chmod +x .git/hooks/commit-msg + +# 如果scp需要密码,确保你的SSH密钥已配置 +``` + +## 一次性安装脚本: + +```bash +#!/bin/bash +echo "安装Gerrit commit-msg钩子..." + +# 进入Git仓库 +cd /e/rjb/zhini_im_android + +# 尝试HTTP方式 +echo "正在下载commit-msg钩子..." +curl -o ".git/hooks/commit-msg" http://101.43.95.130:8080/tools/hooks/commit-msg 2>/dev/null + +if [ $? -eq 0 ]; then + echo "✓ 下载成功" +else + echo "尝试SSH方式..." + scp -p -O -P 29418 rw0067680@101.43.95.130:hooks/commit-msg ".git/hooks/commit-msg" +fi + +# 设置权限 +chmod +x ".git/hooks/commit-msg" +echo "✓ 权限设置完成" + +# 修正提交 +echo "修正提交..." +git commit --amend --no-edit + +# 查看结果 +echo "提交信息:" +git log -1 --pretty=format:"%H%n%an <%ae>%n%ad%n%s%n%b" | head -10 + +echo "现在可以重新推送了:" +echo "git push origin HEAD:refs/for/hotfix-crash" +``` + +## 验证Change-Id: + +```bash +# 查看最近的提交,应该能看到Change-Id +git log -1 + +# 或者查看完整的提交信息 +git show --stat + +# 应该能看到类似这样的内容: +# Change-Id: I1234567890abcdef1234567890abcdef12345678 +``` + +## 重要提示: +1. **每个提交都需要Change-Id**,Gerrit用它来跟踪代码审查 +2. **commit-msg钩子只需要安装一次**,之后的所有提交都会自动生成Change-Id +3. **如果修改历史提交**,需要为每个修改的提交重新生成Change-Id + +现在按照这些步骤操作,应该就能成功推送到Gerrit了! \ No newline at end of file