Help Getting Commit Date From .bat File

So I’ve been using a .bat file (WinXP) to get the rev and hash but I’m running into problems when it comes to getting the date.

This command works on its own from a command prompt:

git show -s --format=“%ci”

but when run from a batch file it returns this: Fatal: invalid --pretty format

I’d like to be able to get the date as well as the rev and hash. Any ideas?

Thanks.

Here’s my modified version of a BAT file posted here a while ago. Sorry, I don’t remember the original author…


@echo off &setlocal EnableDelayedExpansion


REM Retrieves revision hash and deprecated REV_ID

REM Run this from the root folder of your repo


set errormsg=Error: No valid revision information found

set outType=


:menu

cls

echo.

echo	 TrinityCore - Git Rev/Hash locator

echo.

echo	 1. Retrieve latest RevID (-id switch)

echo	 2. Retrieve latest HASH (-hash)

echo	 3. Retrieve both RevID and HASH

echo.

echo	 x = Exit

echo.


set /p m=	Type an option and press enter:

if %m%==* goto menuerror

if %m%==1 goto getID

if %m%==2 goto getHASH

if %m%==3 goto getID_HASH

if %m%==x goto batchExit


:menuerror

CLS

ECHO.

ECHO.

ECHO [ERROR] An error has occured, you will be directed back to the

ECHO [ERROR] main menu.

PAUSE	

GOTO menu


:getID

set outType=-id

goto doSearch


:getHASH

set outType=-hash

goto doSearch


:getID_HASH

set outType=-getID_HASH

goto doSearch


:doSearch


REM Delete existing files

REM Redirect stderr to avoid displaying error messages

2>NUL del _revID.txt

2>NUL del _hash.txt


echo.

echo ^>Searching...


REM Full Hash example: bfbf118e7eef6237a8582043493d55c8298bb208

REM Original command was: git describe --match=init --abbrev=12


for /F "tokens=2,3 delims=-" %%a IN ('"git describe --match=init --abbrev=40"') do (

  set res=false

  if %%c=="" set res=true

  if %%d=="" set res=true

  if "!res!"=="true" (

	  echo.

	  echo !errormsg!

	  goto batchDone

  )


  if "%outType%"=="-id" (


   echo.

   echo ^>RevID = %%a

   echo %%a > _revID.txt

   goto batchDone


  ) else if "%outType%"=="-hash" (


	set str=%%b

	set str=!str:~1!

	echo.

	echo ^>Hash = !str!

	echo !str! > _hash.txt

	goto batchDone


  ) else if "%outType%"=="-getID_HASH" (


	echo.

	echo ^>RevID = %%a

	echo %%a > _revID.txt

	set str=%%b

	set str=!str:~1!

	echo.

	echo ^>Hash = !str!

	echo !str! > _hash.txt


	goto batchDone

  )

)


:batchDone

echo.

set /p wait_cmd=^>Press any key to exit...<NUL

pause>NUL


:batchExit

endlocal

exit /B 1