如何在 git 上手动运行钩子 post-receive?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9159294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:26:29  来源:igfitidea点击:

How can I manually run the hook post-receive on git?

git

提问by nerdess

I've pushed a website to my remote server via Git but got the error

我已通过 Git 将网站推送到我的远程服务器,但出现错误

cannot run post-receive: No such file or directory

So the stuff is on the server, it has just not been deployed to my /public folder.

所以这些东西在服务器上,它只是没有部署到我的 /public 文件夹中。

I do however have a post-receive file so I am not sure why it was not found. Now I thought all I need to do is manually run this post-receive hook to do the checkout though I don't know how...

但是,我确实有一个接收后文件,所以我不确定为什么找不到它。现在我想我需要做的就是手动运行这个 post-receive hook 来进行结账,尽管我不知道如何......

回答by Barend

A hook is an executable shell script. You can execute it from the command line if you need to run it by hand, although constructing the expected stdininuput is somewhat tedious if your repo has more than one head (that is, you use branches). There should be a low-level command to do this for you, but I don't know this offhand.

钩子是一个可执行的 shell 脚本。如果您需要手动运行它,您可以从命令行执行它,尽管stdin如果您的 repo 有多个头(即,您使用分支),构建预期的输入会有些乏味。应该有一个低级命令为您执行此操作,但我不知道这一点。

Assuming a bash shell and a single branch in your git repo...

假设你的 git 仓库中有一个 bash shell 和一个分支......

# Print the log with full hashes and commit subject, so that you can
# figure out which hashes to use for the FROM and TO range.
/path/to/repo$ git log --pretty=%H\ %s

# assuming the FROM commit identifies as 999988887777
# and te TO commit identifies as 000011112222
# (Note: use the full length hashes; I've shortened them for the example)
/path/to/repo$ .git/hooks/post-receive <<MARK
999988887777 000011112222 refs/heads/master
MARK

...the above should work just like the real thing.

...以上应该像真实的东西一样工作。