2012-03-28 122 views
9

我有以下問題。我已經更新了「後收到」 cd到某個目錄,然後在拉回購協議,像這樣部署:git post-receive不能正常工作

#!/bin/bash 
cd /var/www/site 
git pull origin master 

但是每當我做「混帳推起源大師」我的本地機器上,我得到以下內容:

Counting objects: 5, done. 
Delta compression using up to 2 threads. 
(etc..) 
remote: fatal: Not a git repository: '.' 

然而,當我手動cd到/var/www/sitegit pull origin master它出色的作品。

回答

14

使用未設置GIT_DIR如下

#!/bin/bash 
cd /var/www/site || exit 
unset GIT_DIR 
git pull origin master 
exec git-update-server-info 

可以約GIT_DIR在這裏看到更多的信息。 Git Loves the Environment

+0

輝煌我需要的,只是什麼。你介意解釋爲什麼這需要完成? – andy 2012-03-28 11:59:53

+2

'GIT_DIR'是您可以爲各種git命令設置的少數環境變量之一。在post-receive鉤子中,'$ GIT_DIR'總是(?)設置爲'.'。如果你在其他地方使用'cd','git pull'仍然會將'$ GIT_DIR'設置爲''。',並希望在'.'中找到回購,但是你已經移動並且不在那裏。清除它可以讓git回到它的「正常」行爲(在'cd/ed'中查找'./。git')。 – torek 2012-03-29 06:15:26

2

另一種選擇是你可以在命令中提到工作目錄和git目錄。

git --work-tree=/home/user/repos/my_app --git-dir=/home/user/repos/my_app/.git <command> 

e.g:

git --work-tree=/home/user/repos/my_app --git-dir=/home/user/repos/my_app/.git status