Git gives you tools to correct mistakes and reshape history (with care).
- Discard unstaged changes to a file
git restore path/to/file
- Unstage a file
git restore --staged path/to/file
- Amend the last commit (message or staged changes)
git commit --amend
- Move branch pointer (use with care)
git reset --soft HEAD~1# keep index and working treegit reset --mixed HEAD~1# default; keep working treegit reset --hard HEAD~1# discards changes
- Revert a commit (safe on shared branches)
git revert <commitSHA>
Checklist
- You can restore a file and unstage changes
- You understand amend vs revert vs reset
- You know when to avoid reset on shared branches