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

所以它的工作树中没有测试文件

$ git checkout -f 

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

任何想法可能有什么问题?

4

1 回答 1

2

You should set the GIT_WORK_TREE to be sure the checkout is done in the right place:

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

Do not forget to chmod +x the script and be sure that the user pushing has the rights to run the checkout command.

于 2012-01-11T14:01:50.010 回答