Code: Select all
FOR /F %%a IN ('git rev-parse --abbrev-ref HEAD') DO SET branchName = %%a
FOR /F %%a IN ('git rev-list --max-count^=1 %branchName%') DO SET localCommitId = %%a
FOR /F %%a IN ('git rev-list --max-count^=1 origin/%branchName%') DO SET remoteCommitId = %%a
@ECHO branchName = %branchName%
@ECHO localCommitId = %localCommitId%
@ECHO remoteCommitId = %remoteCommitId%
Here's the output I see when I run it:
Code: Select all
>FOR /F %a IN ('git rev-parse --abbrev-ref HEAD') DO SET branchName = %a
>SET branchName = develop
>FOR /F %a IN ('git rev-list --max-count=1 develop') DO SET localCommitId = %a
>SET localCommitId = e4375fa4753b3956e1454020a812cc7591cf606e
>FOR /F %a IN ('git rev-list --max-count=1 origin/develop') DO SET remoteCommitId = %a
>SET remoteCommitId = e4375fa4753b3956e1454020a812cc7591cf606e
branchName = develop
localCommitId =
remoteCommitId =
I don't understand why localCommitId and remoteCommitId are empty despite the printed SET commands setting them to non-empty strings.
I guess the function of git commands is irrelevant to the question because I get the same problem if I replace them with, say, ver.