简体   繁体   English

无法符号链接到.git目录

[英]Unable to symlink to the .git directory

This is probably something silly, but searching around I haven't been able to find the answer. 这可能是愚蠢的事情,但搜索我无法找到答案。 I'm trying to setup pre-commit hooks for my git project in a way that the scripts can be versioned along with the source. 我正在尝试为我的git项目设置预提交挂钩,以便脚本可以与源一起进行版本控制。

It seemed like symlinks are supported and the way to go for this. 它似乎支持符号链接和方法。 When I try to ln with anything in the .git directory I get the error "No such file or directory". 当我尝试使用.git目录中的任何内容时,我收到错误“没有这样的文件或目录”。 Is there something weird about the way the .git directory is setup? 关于.git目录的设置方式有什么奇怪的吗? I'm doing this through cygwin on Windows right now, in case that's pertinent. 我正在通过Windows上的cygwin这样做,以防万一。

For example, the script I'm using to setup the symlinks looks like: 例如,我用来设置符号链接的脚本如下所示:

#/bin/bash

HOOK_NAMES="pre-commit post-commit"
THIS_SCRIPT_DIR=$(dirname $0)
HOOK_DIR=$THIS_SCRIPT_DIR/../.git/hooks

for hook in $HOOK_NAMES; do
    ln -s -f $THIS_SCRIPT_DIR/git-hooks/$hook $HOOK_DIR/$hook
done

Thanks, 谢谢,

==== ====

Followup: This does appear to be an issue with Cygwin, though I haven't been able to find documentation that explains it. 后续:这似乎是Cygwin的问题,尽管我找不到解释它的文档。 This works fine on Linux and OS X. Cygwin is having issues creating symlinks in an implicitly hidden folder (. prefixed). 这在Linux和OS X上运行良好.Cygwin在隐式隐藏文件夹(.prefixed)中创建符号链接时遇到问题。 If anyone knows why I'll happily tag that explanation as an answer. 如果有人知道为什么我会高兴地将这个解释标记为答案。

I don't know why this doesn't work in Cygwin (seems like a bug to me) but in case anyone else has the same issue I was able to work around it by creating the symbolic link from inside the .git folder. 我不知道为什么这在Cygwin中不起作用(对我来说似乎是一个bug)但是如果其他人有同样的问题,我可以通过从.git文件夹内创建符号链接来解决它。 So, for example, from the command line you would go to the .git/hooks folder: 因此,例如,从命令行,您将转到.git / hooks文件夹:

> cd .git/hooks

And then create the link 然后创建链接

> ln -s ../../git-hooks/pre-commit pre-commit

It seems that you are trying to symlink to your .git/hooks from the repository itself. 您似乎正在尝试从存储库本身符号链接您的.git/hooks I don't think this is supported by Git, which would explain the error you are encountering. 我不认为这是Git支持的,这可以解释你遇到的错误。

This answer suggests other approaches, most of them suggesting going to other way around (having .git/hooks being a symlink). 这个答案提出了其他方法,其中大多数建议采用其他方式(将.git/hooks 作为符号链接)。 You might find one that suits you best. 你可能会找到一个最适合你的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM