如何在git pre-push hook中获取远程分支名称

Gum*_*rum 7 git githooks git-branch

文件说:

有关要推送内容的信息在钩子的标准输入上提供了以下形式的行:

<local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF

例如,如果命令+ git push origin master:foreign +运行,则钩子会收到如下所示的行:

refs/heads/master 67890 refs/heads/foreign 12345

如何在pr-hook脚本中访问这些行?

小智 5

可以使用以下方式访问远程分支名称:

while read local_ref local_sha remote_ref remote_sha 
do 
    echo $local_ref
    echo $local_sha 
    echo $remote_ref
    echo $remote_sha
done 
Run Code Online (Sandbox Code Playgroud)

  • 在 v2.21.0 中,这不会打印任何内容 (9认同)