Разработка и Git

Поиск коммита по сообщению и автору

Ищет коммиты по тексту сообщения, автору, датам и пути, не переключая ветки и не меняя файлы.

PowerShell Windows Средний
Скачать Git-FindCommit.ps1
Описание

Что делает скрипт

Скрипт собирает фильтры 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-01
  • powershell -File Git-FindCommit.ps1 -Path . -Author user -File src/app.py
  • powershell -File Git-FindCommit.ps1 -Path . -Message "release" -Limit 50 -Csv commits.csv
Зависимости

Что понадобится

PowerShell 5.1+ Встроен в Windows 10 и 11
Windows Встроен в Windows 10/11 (PowerShell 5.1)
Git 2.40+ Система контроля версий
Windows 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"
}

Скрипты работают с файлами и настройками системы. Перед запуском прочитайте код и проверьте пути. Особенно если скрипт удаляет, перезаписывает или перемещает данные.

CLI 1.0.0

Скачать без браузера

Команда скачает этот файл в текущую папку. CLI работает на Windows, macOS и Linux.

scriptdock get dev-git-find-commit
  • Поиск по всему каталогу
  • Python 3.10+
  • Без внешних пакетов
Скачать CLI

GUI-версия готовится. Подробнее

Категория

Разработка и Git

Git, сборка, тесты, зависимости, логи и обслуживание проектов.