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

标签 git git-branch githooks

文档说:

Information about what is to be pushed is provided on the hook's standard input with lines of the form:

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

For instance, if the command +git push origin master:foreign+ were run the hook would receive a line like the following:

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

我如何访问 pr-hook 脚本中的那些行?

最佳答案

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

while read local_ref local_sha remote_ref remote_sha 
do 
    echo $local_ref
    echo $local_sha 
    echo $remote_ref
    echo $remote_sha
done 

关于git - 如何在git pre-push hook中获取远程分支名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21556589/

相关文章:

git - GitHub 的存储库创建日期是否可信?

git - 使用 Phabricator Permission Denied(publickey) 配置 Git

git - 当提交到子模块的更改时如何在 jenkins 中触发构建?

git - 如何恢复git历史记录

git - 如何让git显示所有本地分支的最近n次提交

git - 如何从 github 上的 Git 分支中删除不需要的文件(如元数据)

.net - 来自 Windows 控制台应用程序的退出代码在 git 钩子(Hook)脚本中不可用

windows - Git:在 Windows 中协调两个具有重复名称(大小写不同)的文件夹,同时保留历史记录

git - 检查 Git 远程 Hook

python - 使用 Anaconda 在 Windows 上使用 pytest githook