git-clone 和结帐后挂钩
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2141492/
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-clone and post-checkout hook
提问by Geoffrey Bachelet
According to the manual, the post-checkout
hook is run after a git checkout
(just as expected) but also after a git clone
(unless you pass --no-checkout
).
根据手册,post-checkout
钩子在 a git checkout
(正如预期的那样)之后运行,但也在 a git clone
(除非你通过--no-checkout
)之后运行。
Very well, now, considering the following:
很好,现在,考虑以下几点:
- you don't have a local repository before a
git clone
- hooks are not synced between remotes
hooks stored in a custom template directory used with(that is actually not true as stated by Jefromi in his answer, but the hook is still not executed)--template
are copied non-executable and therefore notexecuted aftergit clone
- 您在之前没有本地存储库
git clone
- 钩子在遥控器之间不同步
存储在使用 with 的自定义模板目录中的钩子(实际上,正如 Jefromi 在他的回答中所说的那样,但钩子仍然没有执行)--template
被复制为不可执行的,因此不会在之后执行git clone
It seems impossible that a post-checkout
hook ever gets executed after a git clone
. Still, the githooks
man page at http://git-scm.com/docs/githooksexplicitely states a way to avoid it being executed, and also parameters passed in case it is executed, which would indicate it is possible to execute a custom hook after a git-clone
.
似乎不可能post-checkout
在git clone
. 尽管如此,http://git-scm.com/docs/githooks 上的githooks
手册页明确说明了避免执行它的方法,以及在执行时传递的参数,这表明可以执行自定义挂钩之后。git-clone
So, how is it possible? I am obviously missing something here.
那么,怎么可能呢?我显然在这里遗漏了一些东西。
Turns out
结果
采纳答案by Cascabel
I suppose you could make a custom installation - rename the hooks in .../share/git-core/templates/hooks
to remove the .sample
suffix.
我想您可以进行自定义安装 - 重命名挂钩.../share/git-core/templates/hooks
以删除.sample
后缀。
You could also make a template directory full of symlinks to a hooks directory inside the repository, (e.g. post-checkout -> ../../hooks/post-checkout
). Then if the cloned repo contained that particular hook, it'd get executed.
您还可以创建一个包含指向存储库内 hooks 目录的符号链接的模板目录(例如post-checkout -> ../../hooks/post-checkout
)。然后,如果克隆的 repo 包含那个特定的钩子,它就会被执行。
You're right, though, in most cases it will not happen.
不过,您是对的,在大多数情况下它不会发生。
Edit: I just tested it, and the --template
option does appear to preserve permissions, so that's a much more straight-forward way to make it happen. What'd you see to indicate that it stripped that bit?
编辑:我刚刚对其进行了测试,该--template
选项似乎确实保留了权限,因此这是实现它的更直接的方法。你看到了什么表明它剥离了那一点?
The final say on versions: You're looking at documentation online for a newer version of git than you're using. This feature was added in dfa7a6c (clone: run post-checkout hook when checking out); git describe says this wasn't included until v1.6.2-rc2.
关于版本的最终决定权:您正在在线查看比您正在使用的 git 版本更新的 git 文档。这个功能是在dfa7a6c中添加的(clone:结账时运行post-checkout hook);git describe 说这直到 v1.6.2-rc2 才包括在内。
回答by Greg Bacon
From the githooks documentation:
When git-initis run, a handful of example hooks are copied into the
hooks
directory of the new repository, but by default they are all disabled. To enable a hook, rename it by removing its.sample
suffix.
当git-init运行时,一些示例钩子被复制到
hooks
新存储库的目录中,但默认情况下它们都是禁用的。要启用挂钩,请通过删除其.sample
后缀来重命名。
This initialization takes place as part of creating a clone—note the call to init_db
in builtin-clone.c
.
此初始化作为创建克隆的一部分发生 - 请注意对init_db
in的调用builtin-clone.c
。
For example:
例如:
$ cat /tmp/my-git-template/hooks/post-checkout #! /bin/bash echo "Hello from ##代码##" $ git clone --template=/tmp/my-git-template file:///tmp/repo.git my-clone Initialized empty Git repository in /tmp/my-clone/.git/ remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done. Hello from .git/hooks/post-checkout