- 1 year ago
Capturing git commit date (--format=%ci) in a Windows batch file?
In a Windows batch file, you can capture the commit date from Git using the --format=%ci
option. Here's an example of how you can do it:
batch@echo off
REM Run git log command and capture the commit date
for /f "usebackq tokens=*" %%d in (`git log -1 --format^=%ci%`) do set "commit_date=%%d"
REM Print the captured commit date
echo Commit Date: %commit_date%
pause
In this example:
The
for /f
loop runs thegit log
command with the--format=%ci
option to retrieve the commit date of the latest commit.The
tokens=*
option ensures that the entire commit date is captured, even if it contains spaces.The
do set "commit_date=%%d"
statement assigns the captured commit date to thecommit_date
variable.Finally, the script outputs the commit date using
echo %commit_date%
.
You can adjust this script according to your requirements. For example, you can modify the git log
command to retrieve commit dates for specific commits or branches.
Please note that the script assumes that Git is installed and properly configured on the Windows system. Make sure to run the script in a directory that contains a Git repository or adjust the script to target the desired repository.