如何修改git post-update挂钩以仅在一个(主)分支上激活? [英] How can I modify git post-update hook to only activate on one (master) branch?

查看:80
本文介绍了如何修改git post-update挂钩以仅在一个(主)分支上激活?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Web主机上设置了一个裸仓库,并克隆了一个仓库,每当将更改推送到裸仓库时,该仓库就会更新.虚拟主机上的克隆存储库实质上是产品" ,它位于public_html目录中.我非常仔细地遵循了该网站上的说明:

I set up a bare repo on my web host and cloned a repo off of it that will be updated whenever changes are pushed to the bare repo. The cloned repo on the web host is essentially "production," it sits in the public_html directory. I followed the instructions on this site pretty closely:

http://www.ibm.com/developerworks/web/library /wa-git/

它指示我在裸仓库中创建一个更新后"钩子:

It instructed me to make a 'post-update' hook in the bare repo:

#!/bin/bash 
WEB_DIR="<web_dir>"
export GIT_DIR="$WEB_DIR/.git"
pushd $WEB_DIR > /dev/null
git pull
popd > /dev/null

如果我仅在master分支上工作,这是一个很棒的VCS解决方案.

This is a great VCS solution if I'm only working on the master branch.

当我在位置A时,我想克隆裸仓库,开始在分支"newstuff"上工作,提交更改,然后将其推送到裸仓库,以便如果我转到位置B,我可以克隆裸仓库,并可以访问"newstuff".但是我不希望通过更新后脚本更新制作" .

When I'm at location A, I want to clone the bare repo, start working on branch "newstuff", commit the changes, and then push it to the bare repo so that if I go to location B, I can clone the bare repo and have access to "newstuff." But I don't want "production" to be updated via the post-update script.

有没有一种方法可以修改我的更新后脚本,使其仅在master分支上进行更新时执行它的工作?

Is there a way I can modify my post-update script to only do its thing when an update is made on the master branch?

推荐答案

已更新的ref作为参数传递给该钩子.这意味着您可以使用case检查

The refs that were updated are passed to the hook as arguments. This means that you can check for master using case:

case " $* " in
*' refs/heads/master '*)
        # Do stuff
        ;;
esac

顺便说一句,服务器上的git pull仅会获取其他分支,如果主服务器未更新,则不会修改您的工作目录,因此这并不是必需的(除非您担心性能)也许).

By the way, git pull on the server will only fetch the other branches, but won't modify your working directory if master was not updated, so this isn't really necessary (except when you're concerned about performance perhaps).

另请参阅有关该钩子的官方文档: http://schacon.github .com/git/githooks.html#post-update

Also see the official documentation about the hook: http://schacon.github.com/git/githooks.html#post-update

这篇关于如何修改git post-update挂钩以仅在一个(主)分支上激活?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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