1

I've got some files I just committed in my 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

Now I want to capture the paths and do something else with them, but the git diff command doesn't produce(?) any lines for FOR /F to iterate over:

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>

What's going on here? At first I expected it was some mistake in my syntax, but diffing against other targets works inside the for-loop. For example, "master^^" proves that it's not just the escape character playing havoc:

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 ClaimCenter/modules/configuration/gsrc/citizens/cc/pcf_gs/team/TeamTabLastUser.gs

  • We all know CMD.EXE is idiosyncratic to say the least but what's extra-frustrating is how the only case I need (files changed in HEAD) is the only case I've found that doesn't work! – gws Oct 11 '18 at 16:41
0

Double-escape "head^" to "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

When CMD runs the quoted command a second round of expansion takes place so ^^ becomes ^ and then . In fact, the test case diffing against "master^^" doesn't prove anything since it ends up with no carets left. The original command line simply diffed HEAD against HEAD which of course has no files changed at all.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.