Windows 下的 Git 钩子

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22074247/
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-09 11:24:57  来源:igfitidea点击:

Git Hook under Windows

windowsgitposthook

提问by Ramzendo

I have the following code to checkout in a working directory in the hook post-receive:

我有以下代码可以在接收后挂钩的工作目录中签出:

#!/bin/sh
git --work-tree=d:/websites/__gitweb --git-dir=d:/_gitrepo.git/ checkout -f

Unfortunately it doesn't seem to work. However, the command does work when I enter just this in the windows command line (cms):

不幸的是,它似乎不起作用。但是,当我在 Windows 命令行 (cms) 中输入此命令时,该命令确实有效:

git --work-tree=d:/websites/__gitweb --git-dir=d:/_gitrepo.git/ checkout -f

I have checked the permissions and the executing attributes but nothing.

我已经检查了权限和执行属性,但什么也没有。

UPDATE:

更新:

I think I'm getting closer. Now I know what the problem is but I don't know why is this happening. The hook is actually being triggered but I receive this message:

我想我越来越近了。现在我知道问题出在哪里,但我不知道为什么会这样。钩子实际上被触发了,但我收到了这条消息:

remote: Starting copy from repository to work tree...
remote: fatal: Not a git repository: 'd:/_gitrepo.git/'
remote: Finished.

I have tried to change the path of d: to the whole network path but it still doesn't work. If I go to the remote repository and I do a git log, the changes are there and if I run the hook with sh, it works. Why is it saying that it is not a git repository when clearly it is?

我试图将 d: 的路径更改为整个网络路径,但它仍然不起作用。如果我转到远程存储库并执行 git log,更改就在那里,如果我使用 sh 运行钩子,它就可以工作。为什么说它不是一个 git 存储库,但它显然是?

回答by Ramzendo

I finally got it working! This is really weird. I had to type a pwdto see where actually is the batch being located and it showed the hook location on the server. However, in the next line I added a hostnameand it showed me my local hostname. Then I add the whole path just like:

我终于让它工作了!这真的很奇怪。我必须键入 apwd才能查看批次的实际位置,并显示了服务器上的挂钩位置。但是,在下一行中,我添加了一个hostname,它显示了我的本地主机名。然后我添加整个路径,就像:

#!/bin/sh
echo "Starting copy from repository to work tree..."
pwd
hostname
git --work-tree=//remotehost/d$/Webseiten/__gitweb --git-dir=//remotehost/d$/_gitr
epo.git checkout -f
echo "Finished."

I hope this solution works for someone

我希望这个解决方案适用于某人

回答by VonC

For a shell script (and those hook scripts will be executed as shell, even in Windows, through the msys layer of msysgit), you could use a different sort of path:

对于 shell 脚本(并且那些钩子脚本将作为 shell 执行,即使在 Windows 中,通过msysgit 的 msys 层),您可以使用不同类型的路径:

#!/bin/sh
git --work-tree=/d/websites/__gitweb --git-dir=/d/_gitrepo.git/ checkout -f

See also other possibilities with "Posix path conversion in MinGW"

看到“还有其他的可能性在MinGW的Posix的路径转换