繁体   English   中英

Git post-receive hook 无法结帐,致命:你在一个尚未出生的分支上

[英]Git post-receive hook fails to checkout, fatal: You are on a branch yet to be born

在我的服务器上,在/home/user/git/domain.com.git/ ,我运行了git init --bare ,然后在hooks dir 和chmod +x hooks/post-receive创建了post-receive文件。 我使用ls -la来验证它是可执行的。

post-receive文件:

mkdir /home/USER/pub/domain.com
GIT_WORK_TREE=/home/USER/pub/domain.com git checkout -f
GIT_WORK_TREE=/home/USER/pub/domain.com git reset --hard

我从本地执行git push remotename branchname并得到错误:

remote: fatal: You are on a branch yet to be born

它还显示:

To ssh://domain.com/~/git/domain.com.git
   oldcommithash..newhash  branchname -> branchname

我知道 post-receive 钩子正在运行,因为我的mkdir给了我一个目录已经存在的错误,这是意料之中的,并且在我使用此设置的其他站点上不会出现问题。

我也有这个问题git push remotename HEAD这是我想要使用的,最终,用于更简单的脚本。

我最新的hooks/post-receive脚本,它将使用最近的推送更新/home/user/PATH

#!/bin/bash

user=REMOTE_USER_NAME
path=pub/domain.com

# Loop over all pushed branches
c=0;
while read oldrev newrev refname
do
    # track count of branches
    c=$((c + 1))
    branch=$(git rev-parse --symbolic --abbrev-ref "$refname")
done
# If more than one branch was pushed, give an error & return
if [[ $c -gt 1 ]];then
    echo ""
    echo "Multiple branches were pushed. Cannot update remote site."
    echo ""
    return;
fi
# Make the directory. Gives an error if it exists, but who cares?
mkdir "/home/${user}/${path}"

# Checkout the pushed branch & reset --hard
GIT_WORK_TREE="/home/${user}/${path}" git checkout -f "${branch}"
GIT_WORK_TREE="/home/${user}/${path}" git reset --hard

参考

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM