如何使用 windows 批处理提取 GIT 日志

How to extract GIT logs using windows batch

@echo off
setlocal EnableDelayedExpansion

set GitPath="C:\Program Files\Git\bin\"
set NamFile="test.txt"
set /A DatExpo=0
set OutMesg=""

call %GitPath%git.exe log > %NamFile%

for /F "tokens=*" %%i in ('type "%NamFile%"') do (

  set x=%%i
  echo 1: DatExpo is %DatExpo% >> aaa.txt
  echo 1: Compare /!x:~0,5!/ and /Date:/ >> aaa.txt
  if "!x:~0,5!"=="Date:" (
    set /A DatExpo=%DatExpo%+1
  )

  echo 2: DatExpo is %DatExpo% >> aaa.txt
  if "!x:~0,6!"=="commit" (
    if %DatExpo%==1 (
      goto :outBreak
    )
  )

)

:outBreak

我正在尝试从 GIT 日志中提取日期和日志消息,如下所示:

commit c0a3377e5144c37bb3cadd93ef68167ef3097703
Author: ------------------------------------
Date:   Thu Jun 14 17:40:27 2018 +0300

    Relocated: File line golden retriever ( who's a good boy )

commit 42339bbdce74a76889d46714de09ed7b0bf8b955
Author: ------------------------------------
Date:   Tue Jun 12 13:05:38 2018 +0300

    Added: Feature A

BAT文件必须return:

Date:   Thu Jun 14 17:40:27 2018 +0300
Relocated: File line golden retriever ( who's a good boy )

我在文件 aaa.txt 中有以下内容:

1: DatExpo is 0 
1: Compare /Date:/ and /Date:/ 
2: DatExpo is 0 
1: DatExpo is 0 

给出了什么以及为什么未设置变量和比较两个字符串?!

我已将所有 % 替换为 !现在可以使用了!

@echo off
setlocal EnableDelayedExpansion

set GitPath="C:\Program Files\Git\bin\"
set NamFile="test.txt"
set /A DatExpo=0
set OutMesg="out.txt"

del OutMesg

call !GitPath!git.exe log > !NamFile!

for /F "tokens=*" %%i in ('type "!NamFile!"') do (
  set x=%%i
  if "!x:~0,5!"=="Date:" (
    set /A DatExpo=!DatExpo!+1
  )
  if "!x:~0,6!"=="commit" (
    if !DatExpo!==1 (
      goto :outBreak
    )
  )
  if "!DatExpo!"=="1" (
    echo !x! >> !OutMesg!
  )
)

echo OutMesg

:outBreak