Панель состояния репозитория
Собирает ветку, upstream, ahead/behind, счётчики изменений, stash и последние коммиты в одном отчёте.
Что делает скрипт
Скрипт читает git status и git log, но не выполняет fetch, commit или reset. Он показывает, сколько файлов подготовлено, изменено, не отслеживается и конфликтует. Удобно запускать в начале рабочего дня, чтобы быстро понять состояние проекта.
Быстрый старт
powershell -File Git-StatusDashboard.ps1 -Path C:\Users\user\src\app
Скачайте файл, откройте терминал в папке со скриптом и выполните команду. Запускайте в PowerShell 5.1 или PowerShell 7.
Другие варианты
powershell -File Git-StatusDashboard.ps1 -Path .powershell -File Git-StatusDashboard.ps1 -Path D:\Projects\app
Что понадобится
Встроен в Windows 10/11 (PowerShell 5.1)
winget install Git.Git
Git-StatusDashboard.ps1
[CmdletBinding()]
param(
[string]$Path = "."
)
$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"
}
$branch = ((& git -C $repo rev-parse --abbrev-ref HEAD 2>$null) -join "`n").Trim()
$head = ((& git -C $repo rev-parse --short HEAD 2>$null) -join "`n").Trim()
if ($LASTEXITCODE -ne 0) {
Write-Host "Repository has no commits yet: $repo"
exit 0
}
$tracking = ((& git -C $repo rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>$null) -join "`n").Trim()
$ahead = 0
$behind = 0
if ($LASTEXITCODE -eq 0 -and $tracking) {
$counts = ((& git -C $repo rev-list --left-right --count "HEAD...$tracking" 2>$null) -join " ").Trim()
$parts = $counts -split '\s+'
if ($parts.Count -ge 2) {
$ahead = [int]$parts[0]
$behind = [int]$parts[1]
}
}
$staged = 0
$unstaged = 0
$untracked = 0
$conflicted = 0
$statusLines = @(& git -C $repo status --porcelain=v1 2>$null)
foreach ($line in $statusLines) {
if ([string]::IsNullOrWhiteSpace($line) -or $line.Length -lt 2) {
continue
}
$x = [string]$line[0]
$y = [string]$line[1]
if ($x -eq '?' -and $y -eq '?') {
$untracked++
continue
}
if ($x -eq 'U' -or $y -eq 'U' -or ($x -eq 'A' -and $y -eq 'A') -or ($x -eq 'D' -and $y -eq 'D')) {
$conflicted++
continue
}
if ($x -ne ' ') {
$staged++
}
if ($y -ne ' ') {
$unstaged++
}
}
$stashes = @(& git -C $repo stash list 2>$null).Count
Write-Host "Repository: $repo"
Write-Host "Branch: $branch ($head)"
if ($tracking) {
Write-Host "Upstream: $tracking, ahead $ahead, behind $behind"
} else {
Write-Host "Upstream: not configured"
}
Write-Host "Changes: staged $staged, unstaged $unstaged, untracked $untracked, conflicts $conflicted"
Write-Host "Stashes: $stashes"
Write-Host ""
Write-Host "Recent commits:"
& git -C $repo log -5 --date=short --pretty=format:'%h %ad %an %s'
Write-Host ""
Скрипты работают с файлами и настройками системы. Перед запуском прочитайте код и проверьте пути. Особенно если скрипт удаляет, перезаписывает или перемещает данные.