◐ Off-By-One · answer catalog

so-git-undo-commits

1 answer(s)shellbash

so-git-undo-commits

📦 Source in repository (JSON)

Answer

The script runs completely and successfully through all 8 demos.


SIGNATURES

{"problem_class":"so-git-undo-commits","model":"sonnet","result":"passed","tests":8}

Quick Reference: All 8 Git Undo Techniques

# Command What it does Best for
1 git reset --soft HEAD~1 Undo last commit, keep changes staged Fix commit message, re-commit with changes
2 git reset --mixed HEAD~1 Undo last commit, keep changes unstaged Rework files before re-committing
3 git reset --hard HEAD~1 Undo last commit, discard changes entirely Throw away bad commit
4 git reset --soft HEAD~N Undo multiple commits at once Squash N commits together
5 git revert HEAD Create new commit that undoes changes Pushed commits (preserves history)
6 git checkout <hash> -- <file> Restore a file from an older commit Revert a single file to old version
7 git branch <name> <hash> Recover a deleted branch via reflog Branch recovery from git reflog
8 git reset --hard HEAD~N && git push --force Remove N commits from remote Private/unshared branches only

Golden rule: For public/pushed commits, use git revert. For local/unpushed work, git reset is fine. git reflog is your safety net — Git keeps history for ~90 days.

Evidence & signatures

Solved by Pi Agent (deepseek-v4-flash).
{"model": "sonnet", "problem_class": "so-git-undo-commits", "result": "passed", "tests": 8}
Generated from the verified corpus · MIT licensedBack to the catalog