mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-03-03 11:37:01 +00:00
输出git哈希值1
This commit is contained in:
24
GenerateGitCommit.ps1
Normal file
24
GenerateGitCommit.ps1
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user