Git post-receive hook用于推送部署,仅适用于master [英] Git post-receive hook for push-to-deploy only works with master
问题描述
@server:〜$ mkdir -p / home / myuser / domain.git&& chmod 770 /home/myuser/domain.git&& cd /home/myuser/domain.git&& git init --bare
使用post-receive钩子:
@server:〜$ nano hooks / post-receive
钩子脚本是:
#!/ bin / sh
git --work-tree = / var / www / domain --git-dir = / home / myuser / domain.git checkout -f
它有权执行:
@server:〜$ chmod + x hooks / post-receive
然而,当我推送到 master 分支时,它只会改变网站。
为什么?即使我推送到另一个分支,远程 HEAD 始终是 master 。
您默认会检查master分支。需要指定结账的分支,具体取决于刚刚推送和接收的分支。
以下是具有特定分支结账的钩子示例:
#!/ bin / bash
while read oldrev newrev ref
do
branch =` echo $ ref | cut -d / -f3`
GIT_WORK_TREE = / path / to / local / checkout git checkout -f $ branch
done
确保不 同时推送多个分支,或只检出最后一个分支。
I have a remote bare git repository created following:
@server:~$ mkdir -p /home/myuser/domain.git && chmod 770 /home/myuser/domain.git && cd /home/myuser/domain.git && git init --bare
With a post-receive hook:
@server:~$ nano hooks/post-receive
The hook script is:
#!/bin/sh
git --work-tree=/var/www/domain --git-dir=/home/myuser/domain.git checkout -f
It has permission to execute:
@server:~$ chmod +x hooks/post-receive
However, it only changes the website when I push to the master branch.
Why? The remote HEAD is always master, even if I push to another branch.
By default, it checkout the master branch.
You would need to specify which branch to checkout, depending on the branch which has just been pushed and received.
Here is an example of a hook with a specific branch checkout:
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
GIT_WORK_TREE=/path/to/local/checkout git checkout -f $branch
done
Be sure to not push multiple branches at the same time, or only the last branch would be checked out.
这篇关于Git post-receive hook用于推送部署,仅适用于master的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!