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

Сводка git blame по авторам

Считает строки файла по авторам и показывает проценты, не изменяя ни файл, ни историю.

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

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

Скрипт разбирает вывод git blame --line-porcelain и агрегирует количество строк по автору. Можно ограничить период через Since. Это быстрый способ понять, кто и сколько поддерживает конкретный файл, без построчного вывода blame.

Запуск

Быстрый старт

powershell -File Git-BlameSummary.ps1 -Path . -File src/app.py

Скачайте файл, откройте терминал в папке со скриптом и выполните команду. Запускайте в PowerShell 5.1 или PowerShell 7.

Примеры

Другие варианты

  • powershell -File Git-BlameSummary.ps1 -Path . -File README.md
  • powershell -File Git-BlameSummary.ps1 -Path . -File src/app.py -Since 2025-01-01 -Csv blame.csv
Зависимости

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

PowerShell 5.1+ Встроен в Windows 10 и 11
Windows Встроен в Windows 10/11 (PowerShell 5.1)
Git 2.40+ Система контроля версий
Windows winget install Git.Git
Исходник

Git-BlameSummary.ps1

[CmdletBinding()]
param(
    [string]$Path = ".",
    [Parameter(Mandatory = $true)]
    [string]$File,
    [string]$Since,
    [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"
}

$fullPath = Join-Path $repo $File
if (-not (Test-Path -LiteralPath $fullPath -PathType Leaf)) {
    throw "File not found: $fullPath"
}

$gitArgs = @('blame', '--line-porcelain')
if ($Since) {
    $gitArgs += "--since=$Since"
}
$gitArgs += @('--', $File)

$lines = @(& git -C $repo @gitArgs 2>$null)
if ($LASTEXITCODE -ne 0) {
    throw "git blame failed."
}

$counts = @{}
$total = 0
foreach ($line in $lines) {
    if ($line -like 'author *') {
        $author = $line.Substring(7)
        $total++
        if ($counts.ContainsKey($author)) {
            $counts[$author]++
        } else {
            $counts[$author] = 1
        }
    }
}

if ($total -eq 0) {
    Write-Host "No blame lines found."
    exit 0
}

$rows = $counts.GetEnumerator() | ForEach-Object {
    [pscustomobject]@{
        Author  = $_.Key
        Lines   = $_.Value
        Percent = [math]::Round(100.0 * $_.Value / $total, 1)
    }
} | Sort-Object Lines -Descending

Write-Host "File: $File, lines: $total"
$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-blame-summary
  • Поиск по всему каталогу
  • Python 3.10+
  • Без внешних пакетов
Скачать CLI

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

Категория

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

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