![](/img/trans.png)
[英]git - remote: fatal: you are on a branch yet to be born, using 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.