Сводка git blame по авторам
Считает строки файла по авторам и показывает проценты, не изменяя ни файл, ни историю.
Что делает скрипт
Скрипт разбирает вывод 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.mdpowershell -File Git-BlameSummary.ps1 -Path . -File src/app.py -Since 2025-01-01 -Csv blame.csv
Что понадобится
Встроен в Windows 10/11 (PowerShell 5.1)
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"
}
Скрипты работают с файлами и настройками системы. Перед запуском прочитайте код и проверьте пути. Особенно если скрипт удаляет, перезаписывает или перемещает данные.