在git钩子中,当前的工作目录保证在git仓库中? [英] In a git hook is the current working directory guaranteed to be within the git repository?

查看:105
本文介绍了在git钩子中,当前的工作目录保证在git仓库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,似乎git挂钩在当前目录设置为存储库的根目录下运行。不过,我在git文档中看不到任何保证。我应该依赖当前的工作目录来定位git存储库,还是有更好的方法来解决与钩子关联的git存储库? 解决方案

它基于为环境变量 GIT_DIR 设置的值。它在钩子开始运行时被设置到仓库的根目录。许多钩子,尤其是那些从另一个仓库进行拉取的钩子,根据需要取消设置(并重置)该环境变量。


Experimentally it seems that git hooks get run with the current directory set to be the root of the repository. However, I can't see any guarantee about that in the git documentation. Should I rely on the current working directory to locate the git repository, or is there a better way to work out the git repository associated with the hook?

解决方案

It is based on the value set for environment variable GIT_DIR. It is set to the root of the repository when the hook starts running. Many hooks, especially those doing a pull from another repo, unset ( and reset) this environment variable as needed.

这篇关于在git钩子中,当前的工作目录保证在git仓库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆