FOR 循环命令无输出

FOR 循环命令无输出

我在 git repo 中刚刚提交了一些文件:

C:\core\guidewire\Release\5.3_MT1\ClaimCenter>git diff --name-only head^^ ClaimCenter/modules/configuration/config/web/pcf/TabBar.pcf ClaimCenter/modules/configuration/config/web/pcf/team/user/TeamUserClaims.pcf ClaimCenter/modules/configuration/gsrc/citizens/cc/pcf_gs/team/TeamTabLastUser.gs

现在我想捕获路径并用它们做其他的事情,但是命令git diff没有产生(?)任何可以FOR /F迭代的行:

C:\core\guidewire\Release\5.3_MT1\ClaimCenter>for /f %p in ('git diff --name-only head^^') do @( echo %p )

C:\core\guidewire\Release\5.3_MT1\ClaimCenter>

这里发生了什么?起初我以为是我的语法出了问题,但在 for 循环中,与其他目标进行比较是可行的。例如,“master^^”证明不仅仅是转义字符造成了混乱:

C:\core\guidewire\Release\5.3_MT1\ClaimCenter>for /f %p in ('git diff --name-only master^^') do @( echo %p ) ClaimCenter/modules/configuration/config/rules/Reopened/ClaimReopened_dir/CRO05000ApplyCustomReopenRule_dir/CRO05010AssignToOriginalAdjuster.gr ClaimCenter/modules/configuration/config/rules/Reopened/ClaimReopened_dir/CRO05000ApplyCustomReopenRule_dir/CRO05030DefaultAssignment.gr ClaimCenter/modules/configuration/config/web/pcf/TabBar.pcf ClaimCenter/modules/configuration/config/web/pcf/team/user/TeamUserClaims.pcf索赔中心/模块/配置/gsrc/citizens/cc/pcf_gs/团队/TeamTabLastUser.gs

答案1

将“head^”双击转义为“head^^^^”

C:\core\guidewire\Release\5.3_MT1\ClaimCenter>for /f %p in ('git diff --name-only head^^^^') do @(echo %p)
ClaimCenter/modules/configuration/config/web/pcf/TabBar.pcf
ClaimCenter/modules/configuration/config/web/pcf/team/user/TeamUserClaims.pcf
ClaimCenter/modules/configuration/gsrc/citizens/cc/pcf_gs/team/TeamTabLastUser.gs

当 CMD 运行引用的命令时,会发生第二轮扩展,因此^^变成^然后。实际上,与“master^^”进行比较的测试用例并不能证明任何事情,因为它最终没有留下任何插入符号。原始命令行只是将 HEAD 与 HEAD 进行比较,而 HEAD 当然没有任何文件更改。

相关内容