Git Core Commands and Disaster Recovery Cheat Sheet
This quick reference guide summarizes high-frequency Git commands.
1. Daily Workspace Workflow
git status: Inspect untracked and modified file states.git add .: Stage all current modifications.git commit -m "msg": Record changes to local history.git diff: Compare unstaged changes.git log --oneline: View simplified commit history.
2. Branching and Integration
git switch -c branchName: Create and switch to a new branch.git merge branchName: Merge changes into the active branch.git rebase main: Rebase active branch commits ontomain.git pull --rebase origin main: Pull remote updates and rebase local commits.
3. Disaster Recovery and Undo Actions
| Command | Action | Risk Level |
git restore file.html | Discard unstaged changes in working directory | High (deletes local changes) |
git restore --staged file.html | Unstage a file, keeping its edits | Safe |
git reset --soft HEAD~1 | Undo the last commit, keeping changes staged | Safe |
git reset --hard HEAD~1 | Undo last commit and discard all changes | High (deletes modifications) |
git reflog | List local history, including resets and deletes | Safe |
Published on Last updated: