记一次 git push 引发的错误

282 阅读1分钟

场景还原:

最近跟着教程和资料,搞了俩月的flutter。在我快忘记Swift的时候,组织想起了我,给我安排了新的任务需求。

于是乎,拉取项目代码,修改代码,推送代码。

停~

成功被git命令报错拦下了。


问题一:ERROR: commit 654895c: missing Change-Id in message footer

好在报错的同时,也给出了解决提示

remote: Processing changes: refs: 1, done
remote: ERROR: commit 654895c: missing Change-Id in message footer
remote:
remote: Hint: to automatically insert a Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 8999 xxxxxx@gerrit.xxxxxx.xxx: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://gerrit.xxxxxx.xxx: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

就用给出的提示命令行,进行执行

// 命令行 1
> gitdir=$(git rev-parse --git-dir);
// 命令行 2
> scp -p -P 8999 xxxxxx@gerrit.xxxxxx.xxx:hooks/commit-msg ${gitdir}/hooks/
subsystem request failed on channel 0
scp: Connection closed

问题二:scp: Connection closed

在SSH配置正确,代码拉取正常的情况下,出现这种报错咋整呢?

只需要将提示方法中的 scp -p 改为 scp -O,问题即可解决。

> scp -O -P 8999 xxxxxx@gerrit.xxxxxx.xxx:hooks/commit-msg ${gitdir}/hooks/
commit-msg                                           100% 2992    80.4KB/s   00:00

收尾

当问题都解决之后,不要忘记执行命令

git commit --amend --no-edit
// 推送到远端仓库
git push origin HEAD:refs/for/1.0.2

Snipaste_2023-07-12_13-49-15.png