问题描述:
某些项目要求开发者在提交代码时,commit msg中需要携带ChangeId,否则就会push 失败。
如果在开始clone项目时,我们没有clone with commit msg hook,那么就需要特意执行如下指令:
gitdir=$(git rev-parse --git-dir); scp -p -P 29418 xxxx@xxxx:hooks/commit-msg ${gitdir}/hooks/
其中:xxxx@xxxx 代表个人账户地址。
最近在执行这个指令时,提示无法创建commit msg hook。异常日志如下:
subsystem request failed on channel scp: Connection closed
解决方案:
在scp指令中添加-O 项,如下:
gitdir=$(git rev-parse --git-dir); scp -p -O -P 29418 xxxx@xxxx:hooks/commit-msg ${gitdir}/hooks/
解释如下:
-O: 使用传统的SCP协议进行文件传输,而不是SFTP协议。对于不支持SFTP协议的服务器,强制使用SCP协议是很有必要,以及向后兼容特定的filename通配符模式。