| name | git |
| description | Advanced history manipulation, recovery, and diagnostics. |
Advanced Git Operations
Treat history as a document to be groomed for clarity.
1. History Surgery
git rebase -i HEAD~n
git commit --amend --no-edit
git cherry-pick <hash>
2. Recovery & Undo
git reflog
git reset --hard HEAD@{n}
git reset --soft HEAD~1
git restore <file>
3. Diagnostics & Trace
git log -S "string"
git log -L :<func>:<file>
git blame -L 10,20 <file>
git show --name-only <hash>
4. Maintenance
git stash push -m "msg"
git stash pop
git clean -fd
git worktree add ../path br
Principles
- Atomic Commits: One logical change per commit.
- Linear History: Prefer rebase over merge for feature updates.
- Descriptive Messages: Focus on "why" more than "what".