[CmdletBinding()] param( [string]$Path = ".", [string]$Message, [string]$Author, [string]$Since, [string]$Until, [string]$File, [ValidateRange(1, 1000)] [int]$Limit = 20, [string]$Csv ) $ErrorActionPreference = 'Stop' if (-not (Get-Command git -ErrorAction SilentlyContinue)) { throw "git not found in PATH" } $repo = (Resolve-Path -LiteralPath $Path -ErrorAction Stop).Path $null = & git -C $repo rev-parse --is-inside-work-tree 2>$null if ($LASTEXITCODE -ne 0) { throw "Not a git repository: $repo" } $gitArgs = @('log', '-n', "$Limit", '--date=short', '--pretty=format:%h%x1f%ad%x1f%an%x1f%s') if ($Message) { $gitArgs += @("--grep=$Message", '--regexp-ignore-case') } if ($Author) { $gitArgs += "--author=$Author" } if ($Since) { $gitArgs += "--since=$Since" } if ($Until) { $gitArgs += "--until=$Until" } if ($File) { $gitArgs += @('--', $File) } $lines = @(& git -C $repo @gitArgs 2>$null) if ($LASTEXITCODE -ne 0) { throw "git log failed." } $rows = @() foreach ($line in $lines) { if ([string]::IsNullOrWhiteSpace($line)) { continue } $parts = $line -split ([char]0x1f), 4 if ($parts.Count -lt 4) { continue } $rows += [pscustomobject]@{ Commit = $parts[0] Date = $parts[1] Author = $parts[2] Subject = $parts[3] } } if ($rows.Count -eq 0) { Write-Host "No commits found." exit 0 } $rows | Format-Table -AutoSize if ($Csv) { $rows | Export-Csv -LiteralPath $Csv -NoTypeInformation -Encoding UTF8 Write-Host "CSV saved: $Csv" }