有没有办法在 Git 中签出新分支后触发挂钩?
有没有办法在 Git 中签出新分支后触发挂钩?
Is there a way to trigger a hook after a new branch has been checked out in Git?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有没有办法在 Git 中签出新分支后触发挂钩?
Is there a way to trigger a hook after a new branch has been checked out in Git?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
与其他类似,但验证分支是否已签出一次。
Similar to others but verifies that the branch has been checked out once.
post-checkout
hook 接收三个参数:0
) 还是分支签出 (1
)您可以使用以下事实:从当前 HEAD 创建的分支将具有相同的值对于参数 1 和 2。
限制:
The
post-checkout
hook receives three parameters:0
) or branch checkout (1
)You can use the fact that a branch created from the current HEAD will have the same value for parameters 1 and 2.
Limitations:
git hook 是放置在存储库的特殊位置的脚本,该位置是:
该脚本可以是您可以在您的环境中执行的任何类型,即 bash、python、ruby 等。
签出后执行的挂钩是 结帐后。 来自文档:
示例:
创建钩子(脚本):
钩子示例内容:
注意:第一行的 shebang 表示脚本的类型。
该脚本(git hook)只会捕获传递的三个参数并以人类友好的格式打印它们。
A git hook is a script placed in a special location of your repository, that location is:
The script can be any kind that you can execute in your environment i.e. bash, python, ruby etc.
The hook that is executed after a checkout is post-checkout. From the docs:
Example:
Create the hook (script):
Hook sample content:
Note: The shebang in the first line indicates the type of script.
This script (git hook) will only capture the three parameters passed and print them in a human-friendly format.
如果这些钩子之一不能做到这一点,我会感到惊讶:
https://schacon.github .io/git/githooks.html
也许这个:
If one of these hooks won’t do it I’d be amazed:
https://schacon.github.io/git/githooks.html
Maybe this one: