git-undo ⏪✨
A universal "Ctrl + Z" for Git commands. 🔄
git-undo
tracks every mutating Git command you run and can roll it back with a single git undo
🚀
No reflog spelunking, no cherry‑picks—just instant reversal. ⚡
Table of Contents
- Introduction
- Features
- Installation
- Quick Start
- Usage
- Supported Git Commands
- Examples
- Development & Testing
- Contributing & Feedback
- License
Introduction
git-undo
makes destructive Git operations painless to reverse.
It records each mutating command (commit, add, merge, stash, …) per‑repository in a tiny log file inside .git/git-undo/
,
then generates the matching anti‑command when you call git undo
.
Features
- One‑shot undo for commits, adds, branches, stashes, merges, and more.
- Sequential undo / redo - walk backward or forward through history.
- Verbose & dry‑run modes for full transparency.
- Per‑repository command log you can inspect or clear at any time.
Installation
Prerequisites
- Git
- Go ≥ 1.21 (auto‑upgrades to 1.24 via Go toolchain)
- Zsh or Bash Shells (more shells coming soon)
cURL one‑liner (preferred)
curl -fsSL https://raw.githubusercontent.com/amberpixels/git-undo/main/install.sh | bash
Manual clone
git clone https://github.com/amberpixels/git-undo.git
cd git-undo
./install.sh
Shell‑hook integration
- For zsh:
- For bash:
- The installer drops
scripts/git-undo-hook.bash
into ~/.config/git-undo/
and appends a source
line to your .bashrc
/ .bash_profile
(depending on your OS).
Using go install
go install github.com/amberpixels/git-undo/cmd/git-undo@latest
Quick Start
git add .
git commit -m "oops" # commit, then regret it
git undo # resets to HEAD~1, keeps changes staged (like Ctrl+Z)
git undo # undoes `git add .` as well
Need the commit back?
git undo undo # redo last undo (like Ctrl+Shift+Z)
Usage
Command |
Effect |
git undo |
Roll back the last mutating Git command |
git undo undo |
Re-roll back the last undoed command |
git undo --verbose |
Show the generated inverse command before running |
git undo --dry-run |
Print what would be executed, do nothing |
git undo --log |
Dump your logged command history |
Check the version of git-undo:
git undo version # Standard version command
git undo self version # The same (just a consistent way for other `git undo self` commands)
The version detection works in the following priority:
- Git tag version (if in a git repository with tags)
- Build-time version (set during compilation)
- "unknown" (fallback)
Self-Management Commands
Update git-undo to the latest version:
git undo self update
Uninstall git-undo:
git undo self uninstall
Supported Git Commands
commit
add
branch
stash push
merge
checkout -b
- More on the way—PRs welcome!
Examples
Undo a merge commit:
git merge feature/main
git undo # resets --merge ORIG_HEAD
Undo adding specific files:
git add file1.go file2.go
git undo # unstages file1.go file2.go
Development & Testing
make tidy # fmt, vet, mod tidy
make test # unit tests
make lint # golangci‑lint
make build # compile to ./build/git-undo
make install # installs Go binary and adds zsh hook
Development
To build git-undo with a specific version:
# Using git describe
VERSION=$(git describe --tags --always 2>/dev/null || echo "dev")
go build -ldflags "-X main.version=$VERSION" ./cmd/git-undo
# Or manually specify version
go build -ldflags "-X main.version=v1.2.3" ./cmd/git-undo
Testing
Run the test suite:
go test ./...
Contributing & Feedback
Spotted a bug or missing undo case?
Opening an issue or PR makes the tool better for everyone.
If git-undo
saved your bacon, please star the repo and share suggestions!
License
MIT