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. ⚡
- Introduction
- Features
- Installation
- Quick Start
- Usage
- Supported Git Commands
- Examples
- Development & Testing
- Contributing & Feedback
- License
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.
- 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.
- Git
- Go ≥ 1.21 (auto‑upgrades to 1.24 via Go toolchain)
- Zsh or Bash Shells (more shells coming soon)
curl -fsSL https://raw.githubusercontent.com/amberpixels/git-undo/main/install.sh | bashgit clone https://github.com/amberpixels/git-undo.git
cd git-undo
./install.sh- For zsh:
- The installer drops
scripts/git-undo-hook.zshinto~/.config/git-undo/and appends asourceline to your.zshrc.
- The installer drops
- For bash:
- The installer drops
scripts/git-undo-hook.bashinto~/.config/git-undo/and appends asourceline to your.bashrc/.bash_profile(depending on your OS).
- The installer drops
go install github.com/amberpixels/git-undo/cmd/git-undo@latestgit 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 wellNeed the commit back?
git undo undo # redo last undo (like Ctrl+Shift+Z)| 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)
Update git-undo to the latest version:
git undo self update Uninstall git-undo:
git undo self uninstallcommitaddbranchstash pushmergecheckout -b- More on the way—PRs welcome!
Undo a merge commit:
git merge feature/main
git undo # resets --merge ORIG_HEADUndo adding specific files:
git add file1.go file2.go
git undo # unstages file1.go file2.gomake 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 hookTo 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-undoRun the test suite:
go test ./...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!