输出git哈希值1

This commit is contained in:
2026-02-09 02:04:58 +08:00
parent 9ac476e8ea
commit a01dd4e10c
6 changed files with 78 additions and 3 deletions

24
GenerateGitCommit.ps1 Normal file
View File

@@ -0,0 +1,24 @@
$ErrorActionPreference = "Stop"
$gitPath = "git"
$commitFile = "GitCommit.txt"
try {
$commitHash = git rev-parse HEAD 2>&1
if ($LASTEXITCODE -eq 0) {
$shortHash = $commitHash.Substring(0, 7).Trim()
$shortHash | Out-File -FilePath $commitFile -Encoding UTF8 -NoNewline
Write-Host "Git Commit Hash: $shortHash" -ForegroundColor Green
Write-Host "Full Hash: $commitHash.Trim()" -ForegroundColor Cyan
}
else {
Write-Host "Warning: Not a git repository or git not found" -ForegroundColor Yellow
Write-Host "Using default commit hash: unknown" -ForegroundColor Yellow
"unknown" | Out-File -FilePath $commitFile -Encoding UTF8
}
}
catch {
Write-Host "Error: $_" -ForegroundColor Red
"unknown" | Out-File -FilePath $commitFile -Encoding UTF8
}