这是我的 Windows 批处理文件:
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%
这是我运行它时看到的输出:
>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 =
尽管打印的命令将它们设置为非空字符串,但我不明白为什么localCommitId
并且是空的。remoteCommitId
SET
我猜git
命令的功能与问题无关,因为如果我将它们替换为ver
.