2012-01-11 17 views
1

我已經安裝了以下後得到:混帳後接收不執行

$ cat .git/hooks/post-receive 
#!/bin/env sh 
git checkout -f 

這是可執行文件:

$ l .git/hooks/post-receive 
-rwx--x--x 1 nils nils 30 11. Jan 13:17 .git/hooks/post-receive 

所以,當我推到它從我的本地機器應該檢出和有我在本地做出的改變。但事實並非如此:

地方:

$ cat > testfile 
hello world 

$ git add testfile && git commit -m "added testfile" && git push production master 
[master 9f5232d] added testfile 
1 files changed, 1 insertions(+), 0 deletions(-) 
create mode 100644 testfile 
Counting objects: 4, done. 
Delta compression using up to 2 threads. 
Compressing objects: 100% (2/2), done. 
Writing objects: 100% (3/3), 290 bytes, done. 
Total 3 (delta 1), reused 0 (delta 0) 
To ssh://[…]/ 
    88ce501..9f5232d master -> master 

然後在遠程機器上:

$ git status --short 
D testfile 

所以它不具備testfile將在其工作樹

$ git checkout -f 

$ git status 
# On branch master 
nothing to commit (working directory clean) 

任何想法什麼可能是錯誤的?

回答

2

您應該設置GIT_WORK_TREE以確保結帳在正確的地方做:

#!/bin/env sh 
GIT_WORK_TREE=/var/www/website.org git checkout -f 

不要忘記chmod +x腳本,並確保用戶推動具有運行checkout命令的權利。