【发布时间】:2017-07-22 22:52:27
【问题描述】:
我尝试使用 post receive 将更改推送到我的服务器。 在主路径:/home/user 我执行了这些命令:
mkdir repos
cd repos
mkdir test.git
cd test.git
git init --bare
cd hooks
nano post-receive
我将这些行放在接收后文件中:
#!/bin/sh
git —work-tree=/home/user/public_html/testfolder —git-dir=/home/user/repos/test.git checkout -f
chmod +x post-receive
创建成功。 然后我在我的本地仓库中添加一个新的遥控器:
git remote add prod ssh://user@domain.com:22/home/user/repos/test.git
然后我推: git push -u prod master
我收到了成功消息:
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 430 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To ssh://domain.com:22/home/user/repos/test.git
* [new branch] master -> master
Branch master set up to track remote branch master from prod.
但是测试文件夹(我的工作树)中没有文件 - 为什么?
请帮助我。 谢谢!
【问题讨论】:
-
chmod +x post-receive不会在 post-receive 脚本运行后进入作为要在 稍后 运行的命令。它必须立即运行,以便接收后脚本变为可执行的。在 post-receive 脚本可执行之前,它不会运行。有了那行,运行它可以使它可执行,但首先它必须运行,它还不能运行! -
Hooks 是特定于 repo 的。 Receive 在接收端运行。将钩子放在 prod 服务器的 repo 中以在那里运行它。
-
你在使用哪个操作系统@ronjacob
标签: git git-post-receive