Sco*_*y H 6 git bash shell git-submodules githooks
是否有与此等效的命令始终返回绝对路径?
git rev-parse --git-path hooks
Run Code Online (Sandbox Code Playgroud)
当我在子模块中时,我得到一个绝对路径,但是当我在根存储库中时,我得到
.git/钩子
Git v2.13.0 有--absolute-git-dir:
$ git rev-parse --absolute-git-dir\n/Users/torek/...snip.../.git\nRun Code Online (Sandbox Code Playgroud)\n\n但不是--absolute-git-path,正如您所注意到的,--git-path会产生相对结果:
$ git rev-parse --git-path hooks\n.git/hooks\nRun Code Online (Sandbox Code Playgroud)\n\n不过,如果您有Git 2.13,则可以使用 sh/bash 环境变量前缀方法将它们组合起来:
\n\n$ GIT_DIR=$(git rev-parse --absolute-git-dir) git rev-parse --git-path hooks\n/Users/torek/...[snip].../.git/hooks\nRun Code Online (Sandbox Code Playgroud)\n\n如果不是\xe2\x80\x94,如果你的 Git 版本早于 2.13\xe2\x80\x94,你可以使用readlink -f:
$ GIT_DIR=$(readlink -f $(git rev-parse --git-dir)) git rev-parse --git-path hooks\n/home/vagrant/...snip.../.git/hooks\nRun Code Online (Sandbox Code Playgroud)\n\n(在我笔记本电脑上的某个 Linux 映像中;这个特定的 Linux 映像安装了 Git 2.7.4)。
\n