以Windows格式CMD获取git顶级目录

时间:2016-05-10 18:50:05

标签: git sed cmd

如何将此输出设置为CMD中的变量

git rev-parse --show-toplevel |  sed -e s/\//\\/g 

我试过了:

for /f "delims=" %%A in ('git rev-parse --show-toplevel |  sed -e s/\//\\/g ') 
do set "var=%%A"

1 个答案:

答案 0 :(得分:0)

尝试转义管道(in bat shell, escape is '^'):

SETLOCAL ENABLEDELAYEDEXPANSION
for /f "delims=" %%A in ('git rev-parse --show-toplevel ^|  sed -e s/\//\\/g ') do (
  set "var=%%A"
)
echo "A='%A%'"