git post-receive 未执行

发布于 2024-12-26 02:10:53 字数 1075 浏览 4 评论 0原文

我已经设置了以下 post-receive:

$ 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)

什么想法可能是错误的吗?

I have setup the following post-receive:

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

which is executable:

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

So when I push into it from my local machine it should checkout and have the changes I made locally. But that is not the case:

Local:

$ 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

Afterwards on the remote machine:

$ git status --short
 D testfile

So it does not have the testfile in its working tree

$ git checkout -f 

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

Any Ideas what could be possibly wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿! 2025-01-02 02:10:53

您应该设置 GIT_WORK_TREE 以确保结帐在正确的位置完成:

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

不要忘记chmod +x 该脚本并确保推送的用户有权运行 checkout 命令。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文