Git:仅从接收后挂钩部署目录 [英] Git: Deploy only a directory from post-receive hook

查看:64
本文介绍了Git:仅从接收后挂钩部署目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循了本文我有一个接收后钩子,当前显示为:

 #!/ bin / sh 
git --work -tree = / home / user / example.com --git-dir = / home / user / example.com.git结帐-f

这工作良好-所有文件和目录都已部署。但是,我只想从example.com.git中的Build文件夹中部署文件(我正在使用 Hammer 顺便说一句。)因此并非所有开发文件都可以在实时服务器上使用和查看。



问题:我该如何更改/添加到上述Git命令,以便仅签出/部署Build目录中的内容?



更新:

 #!/ bin / sh 
git- -work-tree = / home / user / example.com --git-dir = / home / user / example.com.git签出-f master-Build /
cd /home/user/example.com
cp -rRp构建/。 。
rm -rf构建


解决方案

将提供给-work-tree -git-dir 的值缩写为 WT REPO 分别使所有内容都不需要水平滚动条就可以容纳。



常规格式应为:

 #!/ bin / sh 
git --work-tree = WT --git- dir = REPO checkout -f-路径

假设 WT 目录,您只想检出存储库中的 Build 文件夹。变成

 #!/ bin / sh 
git --work-tree = WT --git-dir = REPO checkout -f-构建

通常,您可以替换路径部分,其中包含git存储库中的一个或多个文件。根据它们在存储库中的放置方式,将它们指定为相对路径。因此,如果您的git repo看起来像这样:

  FolderOne 
|-FolderTwo
| |-FileOne
|-FolderThree

FolderFour
|-FileFive

您要结帐 FileOne 和所有 FolderFour ,您应该这样做:

  git --work-tree = WT --git-dir = REPO签出-f-FolderOne / FolderTwo / FileOne FolderFour 

更新:



自从我处理了Git钩子之后的一段时间,但是我认为除了它们的stdin和argv之类的一些细节之外,您还可以在其中添加任何内容。在 Build 文件夹而不是 Build 文件夹本身中,可以在后接收挂钩中执行以下操作:

  git --work-tree = WT --git-dir = REPO结帐-f-构建/ 
cd WT
cp -r Build / *。
rmdir构建

所以我们首先签出 Build 目录放入 WT 目录。然后我们将 cd 放入 WT 目录,从 Build 目录,使用 cp -r Build / *。代表当前目录,它是我们仅 cd的 WT 目录进入。完成后,我们将删除现在为空的 Build 目录。



因此,所有 Build 目录现在检出到 WT 目录中,而本身没有 Build 目录。当然,您必须分别用工作树和git存储库的实际路径替换 WT REPO



希望有帮助


Having followed the instructions from this article I have a post-receive hook which currently reads:

#!/bin/sh
git --work-tree=/home/user/example.com --git-dir=/home/user/example.com.git checkout -f

This is working well - all the files and directories are getting deployed. However I'd like to only deploy the files from the Build folder within example.com.git (I'm using Hammer by the way.) so not all the development files are available and viewable on the live server.

Question: What do I alter/add to the above Git command in order to only checkout/deploy what's within the Build directory?

Update: After the discussion in the comments I came to the following, which works in my case.

#!/bin/sh
git --work-tree=/home/user/example.com --git-dir=/home/user/example.com.git checkout -f master -- Build/
cd /home/user/example.com
cp -rRp Build/. .
rm -rf Build

解决方案

I'll abbreviate the values supplied to --work-tree and --git-dir as WT and REPO respectively so that everything can fit without a horizontal scrollbar.

The general form should be:

#!/bin/sh
git --work-tree=WT --git-dir=REPO checkout -f -- paths

Suppose at the WT directory that's being deployed on the live server, you only want to checkout the Build folder in the repository. This becomes

#!/bin/sh
git --work-tree=WT --git-dir=REPO checkout -f -- Build

In general, you can replace the paths portion with one or more files in the git repository. These are specified as relative paths according to how they are placed in the repo. So if your git repo looks like this:

FolderOne
|- FolderTwo
|  |- FileOne
|- FolderThree

FolderFour
|- FileFive

And you want to checkout FileOne and everything FolderFour, you should do:

git --work-tree=WT --git-dir=REPO checkout -f -- FolderOne/FolderTwo/FileOne FolderFour

UPDATE:

It's been some time since I've dealt with Git hooks, but I think other than some details like their stdin and argv, you can put anything inside.

So for checking out everything in the Build folder but not the Build folder itself, you could do something like this in the post-receive hook:

git --work-tree=WT --git-dir=REPO checkout -f -- Build/
cd WT
cp -r Build/* .
rmdir Build

So we first checkout the Build directory into the WT directory. Then we cd into the WT directory, copy everything out from the Build directory using cp -r Build/* . . The . stands for the current directory, which is the WT directory we just cd into. Once that's done, we remove the now empty Build directory.

Hence, everything from the Build directory is now checked out into the WT directory, without the Build directory itself. Of course, you've got to replace WT and REPO by the actual paths to the work tree and git repository respectively.

Hope that helps

这篇关于Git:仅从接收后挂钩部署目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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