Git - 远程:错误:无法运行钩子/后接收:没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11630433/
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
Git - remote: error: cannot run hooks/post-receive: No such file or directory
提问by BobFlemming
I get the error :
我收到错误:
remote: error: cannot run hooks/post-receive: No such file or directory
When trying to push to remote. The post-receivce file exists in the correct location (testnew.git/hooks) and contains:
尝试推送到远程时。post-receivce 文件存在于正确的位置 (testnew.git/hooks) 并包含:
#!/bin/bash2
export GIT_DIR=/var/www/testnew/testnew/.git/
export GIT_WORK_TREE=/var/www/testnew/testnew/
cd /var/www/testnew/testnew/
echo "here we go..."
git fetch
git merge origin/master
git submodule update --init --recursive
I've tried setting permissions on post-receive using:
我尝试使用以下方法设置接收后的权限:
chmod a+x post-receive
But this gives same error. Setting permission to 755 removes the error , but the script does'nt run.
但这给出了同样的错误。将权限设置为 755 会消除错误,但脚本不会运行。
采纳答案by Jan Hudec
This would happen if the hooks/post-receive
file exists, is marked executable, but cannot be executed. It cannot be executed, because the interpreter, /bin/bash2
, either does not exist or is not executable.
如果hooks/post-receive
文件存在,标记为可执行,但无法执行,则会发生这种情况。它无法执行,因为解释/bin/bash2
器 不存在或不可执行。
Replace the /bin/bash2
with name of bash that does exist and is executable on the server.
替换/bin/bash2
bash 的名称,该名称确实存在并且可以在服务器上执行。
(The reason the error looks like this is, that the operating system only returns the error status, "No such file or directory", but does not report which file does not exist. And the code that tried to execute it does not know that the system already read hooks/post-receive
and was looking for /bin/bash2
. All it knows is it tried to run hooks/post-receive
, so that's what it prints).
(错误看起来像这样的原因是操作系统只返回错误状态“没有这样的文件或目录”,而没有报告哪个文件不存在。尝试执行它的代码不知道系统已经读取hooks/post-receive
并正在寻找/bin/bash2
。它所知道的是它试图运行hooks/post-receive
,所以这就是它打印的内容)。
回答by Xtremefaith
In addition (for future reference and documentation on this question) if you were to run echo $SHELL
in your shell you should see an expected result, in this case (based on the approved answer)you would expect /bin/bash
as your result. But another possible problem can be an unseen carriage return.
此外(供将来参考和有关此问题的文档)如果您要echo $SHELL
在 shell 中运行,您应该看到预期的结果,在这种情况下(基于批准的答案),您会期望/bin/bash
结果。但另一个可能的问题可能是看不见的回车。
Try running hooks/post-receive
if you're still having issues, you may get a response like this:
hooks/post-receive
如果您仍然遇到问题,请尝试运行,您可能会得到如下响应:
-bash: hooks/post-receive: /bin/bash^M: bad interpreter: No such file or directory
The key here is the ^M
that is proof that you are in fact getting an unexpected carriage return, otherwise if it had worked you would probably get a hanging response.
这里的关键^M
是证明你实际上得到了一个意外的回车,否则如果它有效,你可能会得到一个挂起的响应。
Fix that and it should fix your problem. The way to do that, use dos2unix
, for example:
解决这个问题,它应该可以解决您的问题。这样做的方法dos2unix
,例如使用:
dos2unix .htaccess
回答by Aminah Nuraini
It was caused by me forgetting to do git init
first.
这是我忘记先做造成的git init
。
回答by I.Ewetoye
Though this question was asked several years ago, but I felt I could add my solution for future readers. In my own case, the following steps solved it:
虽然这个问题是几年前提出的,但我觉得我可以为未来的读者添加我的解决方案。在我自己的情况下,以下步骤解决了它:
- I was sure that I had done
git init --bare
- from my bash console, I ran
which bash
, then I saw that#!/bin/bash
was sufficient - from a bash console, knowing fully well that I am in my bare-repos app folder (equivalent of
~/bare-repos/mysite.git
, I ranhooks/post-receive
to see if this work well. In my own case, I gotbash: hooks/post-receive: /bin/bash^M: bad interpreter: No such file or directory
- Then, I knew that I was suffering from an unexpected carriage return, but I don't want to use
dos2unix
in pythonanywhere. - I opened the post-receive file in pythonanywhere's editor, cleared all the lines, and manually keyed-in the line as opposed to copying and pasting the lines.
- Again, from a bash console, knowing fully well that I am in my bare-repo app folder (equivalent of
~/bare-repos/mysite.git
, I ran hooks/post-receive to see if this work well. In my own case, No error was thrown. - I was good to go.
- 我确信我已经完成了
git init --bare
- 从我的 bash 控制台,我跑了
which bash
,然后我看到这就#!/bin/bash
足够了 - 从 bash 控制台,完全知道我在我的裸仓库应用程序文件夹中(相当于
~/bare-repos/mysite.git
,我跑去hooks/post-receive
看看这是否工作正常。在我自己的情况下,我得到了bash: hooks/post-receive: /bin/bash^M: bad interpreter: No such file or directory
- 然后,我知道我遇到了意外的回车,但我不想
dos2unix
在pythonanywhere中使用。 - 我在 pythonanywhere 的编辑器中打开 post-receive 文件,清除所有行,然后手动键入行而不是复制和粘贴行。
- 再次,从 bash 控制台,完全清楚我在我的裸仓库应用程序文件夹中(相当于
~/bare-repos/mysite.git
,我运行 hooks/post-receive 以查看这是否工作正常。在我自己的情况下,没有抛出错误。 - 我很高兴去。