1.5 KiB
1.5 KiB
History Traps
Reset
git reset --hardloses uncommitted changes PERMANENTLY — no undo--hardvs--softvs--mixed— each moves different things- Reset of pushed commit = history diverges — you need force push
- Reset with untracked files = untracked survive — can surprise you
Revert
- Revert creates NEW commit — doesn't delete the original
- Revert of merge commit needs
-m 1or-m 2— without it, error - Revert of revert = re-applies changes — confusing history
- Revert of old commit can conflict with later commits
Amend
--amendchanges SHA — amended commit is DIFFERENT commit- Amend of pushed commit = same problems as rebase
--amendwithout staging = only changes message- Accidental amend on wrong commit = use reflog to recover
Reflog
- Reflog is LOCAL — doesn't sync with remote
- Reflog expires (default 90 days) — old commits lost
git gccan clean unreachable commits before expiration- Reflog of deleted branch is in HEAD reflog, not branch reflog
Cherry-pick
- Cherry-pick creates new commit with different SHA
- Cherry-picking then merging = duplicate commits in history
- Cherry-pick of merge commit needs
-mflag - Conflicts in cherry-pick = resolve same as rebase
Blame
git blameshows last change, not original author- Blame ignores whitespace changes with
-w git log -p filenameshows full history of changes- Blame on moved code: use
git log --followfor renamed files