提交消息页脚中缺少git-review的Change-Id [英] missing Change-Id in commit message footer for git-review

查看:251
本文介绍了提交消息页脚中缺少git-review的Change-Id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Gerrit克隆了一个空的存储库.我创建了一个名为"new_files"的新分支,并将上游拉入该分支.当我尝试运行git-review时,出现这样的错误:

The outstanding commits are:

6d5d8ac (HEAD, new_files) Change-Id: If528f4dd29638e8c2a8d18a624a289afe390e6e2
cc81223 Merge branch 'master' of UPSTREAM into new_files
d787290 (upstream/master) rename properties to dat
32d76cf rename properties to dat
73d8e05 rename data to properties
e46416e Add file.
8bfcab5 referencing properties
e8b03fc rename data

Do you really want to submit the above commits?
Type 'yes' to confirm, other to cancel: yes
2016-11-15 12:09:54.407178 Running: git branch --color=never
2016-11-15 12:09:54.411090 Running: git log HEAD^1..HEAD
Using local branch name "new_files" for the topic of the change submitted
2016-11-15 12:09:54.416984 Running: git push gerrit HEAD:refs/publish/master/new_files
remote: Processing changes: refs: 1, done
remote: ERROR: missing Change-Id in commit message footer
remote:
remote: Hint: To automatically insert Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 user@:hooks/commit-msg ${gitdir}/hooks/
remote: And then amend the commit:
remote:   git commit --amend
remote:
To ssh://
 ! [remote rejected] HEAD -> refs/publish/master/new_files (missing Change-Id in commit message footer)
error: failed to push some refs to 'ssh://'
2016-11-15 12:09:54.655379 Running: git rev-parse --show-toplevel --git-dir

我试图安装挂钩并使用amend,但这没什么区别.

解决方案

我很想建议提交挂钩未正确安装.另外,我建议从等式中删除git review,直到您可以单独使用git commit --amend(在这种情况下,working表示更改ID在修改提交后出现在提交消息中).

以下是对提交消息挂钩进行故障排除的方法: (我注意到下面的很多内容都假定commit-msg钩子脚本是Shell脚本.请让我知道这个假设是否不正确)

1级:基础知识

  1. 检查提交消息挂钩是否安装在您期望的位置: $ ls -la .git/hooks/commit-msg -rwxr-xr-x 1 az staff 4407 15 Nov 19:00 .git/hooks/commit-msg
    请注意提交消息挂钩的大小不为零,以及('-rwx')脚本可执行的事实.

  2. 尝试通过执行.git/hooks/commit-msg自行执行commit-msg脚本.这应该失败,并带有: sed: : No such file or directory
    这是可以预期的,因为钩子脚本假定它是由git运行的,而不是独立运行的.保持冷静并继续前进.

  3. .git/hooks/commit-msg的顶部(紧接unset GREP_OPTIONS之前)添加以下内容:
    echo "Executing基本名称"$ 0" with args: $@"

  4. 现在尝试执行git commit --amend,对我来说,具有正确安装的钩子的输出如下:
    $ git commit -m "Test commit-msg hook" Executing commit-msg with args: .git/COMMIT_EDITMSG

如果在任何一个步骤中都没有看到上面发布的预期输出,则说明您的挂钩脚本未正确安装.您可以手动将钩子脚本捕获到.git/hooks目录中,并检查它是否可以由正确的用户执行(前者是输出中的git命令执行的操作).

级别2:要求GIT更加详细

如果您只要求很好的话,GIT会揭示更多.注意,这也显示了正在执行的钩子脚本:

$ GIT_CURL_VERBOSE=1 GIT_TRACE=2 git commit --amend 19:13:26.836236 git.c:349 trace: built-in: git 'commit' '--amend' 19:13:27.025894 run-command.c:336 trace: run_command: '/usr/bin/vim' '/Users/some-git-dir/.git/COMMIT_EDITMSG' 19:13:27.026454 run-command.c:195 trace: exec: '/usr/bin/vim' '/Users/some-git-dir/.git/COMMIT_EDITMSG' 19:13:28.497117 run-command.c:336 trace: run_command: '.git/hooks/commit-msg' '.git/COMMIT_EDITMSG' Executing commit-msg with args: .git/COMMIT_EDITMSG 19:13:28.504150 git.c:349 trace: built-in: git 'stripspace' 19:13:28.507498 git.c:349 trace: built-in: git 'config' '--bool' '--get' 'gerrit.createChangeId' [some-branch-blah 1f205cb] Test commit-msg hook Date: Tue Nov 15 19:00:59 2016 +0000 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 a

级别3:像shell脚本一样调试钩子

我怀疑是脚本本身需要检查,但是事实证明如此,那么下一步就是做通常要调试的shell脚本(因为这是默认设置) commit-msg钩子是).

我首先将she-bang线从#!/bin/sh更改为#!/bin/sh -xv,然后在执行git commit --amend

时执行脚本,然后进入超级冗长的输出

I've cloned an empty repository from Gerrit. I've created a new branch called "new_files" and pulled an upstream into it. When I'm trying to run git-review, I get such an error:

The outstanding commits are:

6d5d8ac (HEAD, new_files) Change-Id: If528f4dd29638e8c2a8d18a624a289afe390e6e2
cc81223 Merge branch 'master' of UPSTREAM into new_files
d787290 (upstream/master) rename properties to dat
32d76cf rename properties to dat
73d8e05 rename data to properties
e46416e Add file.
8bfcab5 referencing properties
e8b03fc rename data

Do you really want to submit the above commits?
Type 'yes' to confirm, other to cancel: yes
2016-11-15 12:09:54.407178 Running: git branch --color=never
2016-11-15 12:09:54.411090 Running: git log HEAD^1..HEAD
Using local branch name "new_files" for the topic of the change submitted
2016-11-15 12:09:54.416984 Running: git push gerrit HEAD:refs/publish/master/new_files
remote: Processing changes: refs: 1, done
remote: ERROR: missing Change-Id in commit message footer
remote:
remote: Hint: To automatically insert Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 user@:hooks/commit-msg ${gitdir}/hooks/
remote: And then amend the commit:
remote:   git commit --amend
remote:
To ssh://
 ! [remote rejected] HEAD -> refs/publish/master/new_files (missing Change-Id in commit message footer)
error: failed to push some refs to 'ssh://'
2016-11-15 12:09:54.655379 Running: git rev-parse --show-toplevel --git-dir

I tried to install the hook and to use amend but it makes no difference.

解决方案

I'd be tempted to suggest that the commit hook is not installed properly. Also, I would suggest removing git review from the equation until you can get a git commit --amend working on it's own (working in this case means that the change-id appears in the commit message after an amend commit).

Here is how to troubleshoot the commit message hook: (I noticed that a lot of the below assumes that the commit-msg hook script is a shell script. Let me know if this assumption is incorrect)

Level 1 : The basics

  1. Check that the commit message hook is installed where you expect it to be: $ ls -la .git/hooks/commit-msg -rwxr-xr-x 1 az staff 4407 15 Nov 19:00 .git/hooks/commit-msg
    Notice the non-zero size of the commit message hook as well as the fact that ('-rwx') script is executable.

  2. Try executing the commit-msg script on it's own by doing .git/hooks/commit-msg. This should fail with a : sed: : No such file or directory
    which is ok and expected since the hook script assumes that it is being run by git and not standalone. Keep calm and carry on.

  3. Add the following at the top of .git/hooks/commit-msg (just before unset GREP_OPTIONS):
    echo "Executingbasename "$0"with args: $@"

  4. Now try doing a git commit --amend, for me the output with a correctly installed hook was as follows:
    $ git commit -m "Test commit-msg hook" Executing commit-msg with args: .git/COMMIT_EDITMSG

If you don't see the expected output as posted above in any of the steps then your hook script was not installed properly. You can manually scp the hook script over to .git/hooks directory and check that it is executable by the correct user (the former is what git command in your output does).

Level 2: Asking GIT to be a bit more verbose

GIT will reveal a bit more if you only ask it nicely. Notice that this also shows the hook script being executed:

$ GIT_CURL_VERBOSE=1 GIT_TRACE=2 git commit --amend 19:13:26.836236 git.c:349 trace: built-in: git 'commit' '--amend' 19:13:27.025894 run-command.c:336 trace: run_command: '/usr/bin/vim' '/Users/some-git-dir/.git/COMMIT_EDITMSG' 19:13:27.026454 run-command.c:195 trace: exec: '/usr/bin/vim' '/Users/some-git-dir/.git/COMMIT_EDITMSG' 19:13:28.497117 run-command.c:336 trace: run_command: '.git/hooks/commit-msg' '.git/COMMIT_EDITMSG' Executing commit-msg with args: .git/COMMIT_EDITMSG 19:13:28.504150 git.c:349 trace: built-in: git 'stripspace' 19:13:28.507498 git.c:349 trace: built-in: git 'config' '--bool' '--get' 'gerrit.createChangeId' [some-branch-blah 1f205cb] Test commit-msg hook Date: Tue Nov 15 19:00:59 2016 +0000 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 a

Level 3: Debugging hook like a shell script

I doubt that it is the script itself which needs to be looked at, however if that turns out to be the case, then the next step is to do what you normally would to debug shell scripts (since that is what the default commit-msg hook is).

I would start by changing the she-bang line from #!/bin/sh to #!/bin/sh -xv and then revel in the uber-verbose output as the script is executed when you do a git commit --amend

这篇关于提交消息页脚中缺少git-review的Change-Id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆