我试图从windows中的"git“shell中检索存储库的路径,如下所示
user@CND7293ZVV MINGW64 /c/Work/git/repository/subfolder (master)
$ git rev-parse --show-toplevel
C:/Work/git/repository问题是我想使用ouptut路径从bash脚本中使用它,但它不是bash格式的。我要去找/c/Work/git/repository。是否有任何方法可以直接在中获得路径?
额外信息:目标是将该路径存储在bash脚本中的一个变量中,这与我是从linux终端运行bash还是从git bash运行时无关。
更新:
为了能够在git-bash环境中和本机linux中使用该命令,我们可以使用以下命令:
REPODIR=$(git rev-parse --show-toplevel)
# If we are inside mingw* environment, then we update the path to proper format
if [[ $(uname) == MINGW* ]] ; then REPODIR=$(cygpath -u "${REPODIR}"); fi; echo ${REPODIR}发布于 2018-05-29 09:00:12
在Git命令行上运行时,您有一个名为半路径的buildin实用程序,它执行以下操作:
$ cygpath -u "C:/Work/git/repository"
/c/Work/git/repository可以将它与现有的命令结合起来,在1行中完成所有操作:
$ cygpath -u "$(git rev-parse --show-toplevel)"
/c/Work/git/repositoryhttps://stackoverflow.com/questions/50579937
复制相似问题