我正在尝试编写一个批处理脚本,在git中检查本地mods。我只需要一个是/否输出,但我想排除未跟踪的文件。
下面是在命令行中包含未跟踪文件时所看到的内容:
C:\local_workspace>git status --porcelain
M EWARM/stm32u575xx_flash.icf
M EWARM/stm32u575xx_sram.icf
?? EWARM/bui.h
?? EWARM/gen_build_info_header_git.bat
?? EWARM/test.h
?? EWARM/test2.h我可以使用for命令来处理这个问题:
C:\local_workspace>for /F "delims=" %i in ('git status --porcelain') do (echo [%i])
C:\local_workspace>(echo [ M EWARM/stm32u575xx_flash.icf] )
[ M EWARM/stm32u575xx_flash.icf]
C:\local_workspace>(echo [ M EWARM/stm32u575xx_sram.icf] )
[ M EWARM/stm32u575xx_sram.icf]
C:\local_workspace>(echo [?? EWARM/bui.h] )
[?? EWARM/bui.h]
C:\local_workspace>(echo [?? EWARM/gen_build_info_header_git.bat] )
[?? EWARM/gen_build_info_header_git.bat]
C:\local_workspace>(echo [?? EWARM/test.h] )
[?? EWARM/test.h]
C:\local_workspace>(echo [?? EWARM/test2.h] )
[?? EWARM/test2.h]如果我排除了跟踪的文件,我看到的是:
C:\local_workspace>git status --porcelain --untracked-files=no
M EWARM/stm32u575xx_flash.icf
M EWARM/stm32u575xx_sram.icf现在让我们试试for
C:\local_workspace>for /F "delims=" %i in ('git status --porcelain --untracked-files=no') do (echo [%i])
C:\local_workspace>没有输出!为什么不行?
发布于 2022-09-02 14:37:55
for循环将=视为空白,因此对于所有意图和目的,您的代码都试图处理命令git status --porcelain --untracked-files no,该命令是无效的。
为了保存=,需要使用^:git status --porcelain --untracked-files^=no来转义
https://stackoverflow.com/questions/73583491
复制相似问题