-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgitfix.ps1
More file actions
38 lines (33 loc) · 1.14 KB
/
gitfix.ps1
File metadata and controls
38 lines (33 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<#
.SYNOPSIS
Git fixup commit to a previous commit, selected interactively via fzf.
.DESCRIPTION
Stages all changes, lets you pick a past commit via fzf, then runs:
git commit --fixup <sha>
git rebase --autosquash <sha>~1
.LINK
https://stackoverflow.com/questions/3103589/how-can-i-easily-fixup-a-past-commit
#>
$script:ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
$selected = git log --oneline --color=always | fzf --ansi --no-sort --prompt="Fixup into> "
if (-not $selected) {
Write-Warning "No commit selected, aborting."
exit 0
}
# First token is the short SHA; resolve to full SHA for safety
$shortSha = ($selected -split '\s+')[0]
$sha = git rev-parse $shortSha
$status = Get-GitStatus
if ($status.HasIndex) {
Write-Warning "Only staged files will be committed: $($status.Index -join ' ')"
} elseif ($status.HasUntracked) {
git status --porcelain | sls '^\?\?'
throw "Untracked files! Stage or stash them first."
} else {
# Nothing staged, no untracked — stage all tracked changes
git add --update
}
"Fixing up into $sha ($($selected.Trim()))"
git commit --fixup $sha
git rebase --autosquash "${sha}~1"