脚本获取git工作目录root?

And*_*zos 3 linux git bash

可能重复:
有没有办法在一个命令中获取git根目录?

我正在编写一个bash脚本(实际上是一个Makefile),需要使用一个参数,该参数是一个相对于包含当前目录的git工作目录的根目录.

那是:

 /home/me$ git clone /abc/foo.git

 directory foo created

 /home/me$ cd foo/bar

 /home/me/foo/bar$ execute_script.sh

 hello /home/me/foo/baz
Run Code Online (Sandbox Code Playgroud)

execute_script.sh如下:

 echo hello `git something`/baz
Run Code Online (Sandbox Code Playgroud)

什么是git?它应该返回当前git工作根的绝对路径.

Tec*_*163 10

好吧,如果你知道你将进入酒吧文件夹,你可以尝试:

echo hello `pwd`/../baz
Run Code Online (Sandbox Code Playgroud)

编辑:正如@Andrew Tomazos早些时候指出的那样,你可以做到

echo hello `git rev-parse --show-toplevel`/baz
Run Code Online (Sandbox Code Playgroud)