Поиск коммита по сообщению и автору
Ищет коммиты по тексту сообщения, автору, датам и пути, не переключая ветки и не меняя файлы.
Что делает скрипт
Скрипт собирает фильтры git log из параметров и печатает короткий список с хешем, датой, автором и темой. Поиск по сообщению не учитывает регистр. Результат можно выгрузить в CSV для разбора.
Быстрый старт
powershell -File Git-FindCommit.ps1 -Path . -Message "login" -Author user
Скачайте файл, откройте терминал в папке со скриптом и выполните команду. Запускайте в PowerShell 5.1 или PowerShell 7.
Другие варианты
powershell -File Git-FindCommit.ps1 -Path . -Message "fix" -Since 2025-01-01powershell -File Git-FindCommit.ps1 -Path . -Author user -File src/app.pypowershell -File Git-FindCommit.ps1 -Path . -Message "release" -Limit 50 -Csv commits.csv
Что понадобится
Встроен в Windows 10/11 (PowerShell 5.1)
winget install Git.Git
Git-FindCommit.ps1
[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"
}
Скрипты работают с файлами и настройками системы. Перед запуском прочитайте код и проверьте пути. Особенно если скрипт удаляет, перезаписывает или перемещает данные.