如何在git中的post-receive hook中处理分支上的文件 [英] how to process files on a branch in post-receive hook in git

查看:160
本文介绍了如何在git中的post-receive hook中处理分支上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个远程服务器,我在其上创建了一个裸露的git存储库。



我想创建一个钩子,以便给定脚本在任何给定分支上收到的最新代码上运行。

我知道 post-receive 钩子可以用于它。然而,我想要执行以下操作:


  1. 获取收到代码的分支。

  2. 在临时位置签出代码并对其执行操作。

如何执行上述操作?

解决方案



请参阅 Git post-receive for multiple remote branches and work-trees

 #!/ bin / bash 

while read oldrev newrev ref
do
branch =`echo $ ref | cut -d / -f3`

if [master==$ branch];然后
git --work-tree = / path / under / root / dir / live-site / checkout -f $ branch
echo'Changes push live。'
fi

if [dev==$ branch];然后
git --work-tree = / path / under / root / dir / dev-site / checkout -f $ branch
echo'推送到dev的变化'
fi
完成


I have a remote server on which I have created a bare git repository.

I would like to create a hook so that a given script is run on the latest code received on any given branch.

I know the post-receive hook can be used for it. However I want to do the following:

  1. Get hold of the branch on which code was received.
  2. Checkout the code in a temp location and run an operation on it.

How do I do the above?

解决方案

See both techniques combined in "Git post-receive for multiple remote branches and work-trees":

#!/bin/bash

while read oldrev newrev ref
do
  branch=`echo $ref | cut -d/ -f3`

  if [ "master" == "$branch" ]; then
    git --work-tree=/path/under/root/dir/live-site/ checkout -f $branch
    echo 'Changes pushed live.'
  fi

  if [ "dev" == "$branch" ]; then
    git --work-tree=/path/under/root/dir/dev-site/ checkout -f $branch
    echo 'Changes pushed to dev.'
  fi
done

这篇关于如何在git中的post-receive hook中处理分支上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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