| name | git-and-github |
| description | Portable guidance for git and github. Use when work involves git and github. |
Loading Past Code Changes (git)
| Question | Command |
|---|
| What did I just change? | git diff / git diff --staged |
| What's on this branch vs main? | git log main..HEAD --oneline then git diff main...HEAD -- <path> |
| When did this line appear? | git log -p -S '<exact string>' -- <path> (pickaxe) |
| Who/when last touched these lines? | git blame -L <start>,<end> <path> |
| What's in an old commit? | git show <sha> or git show <sha> -- <path> |
| What shipped recently? | git log --since='1 week ago' --oneline |
| Compare two branches | git diff <a>..<b> -- <path> |
Prefer git log --stat / --name-only to scope before pulling a wide git diff into context.
Recovering Lost Work
- Lost commit:
git reflog → git cherry-pick <sha> or git branch <name> <sha>.
- Discarded uncommitted edits: gone unless they were ever committed (then reflog).
- Stashes:
git stash list, git stash show -p <stash>, git stash apply <stash>.
- Deleted branch tip:
git reflog still has it — recreate with git branch <name> <sha>.
Non-Obvious Git Bits
git log --follow -- <file> traces a file through renames.
git show <branch>:<path> reads a file from another branch without checking out.
git merge-base main HEAD finds where a branch diverged.
git diff --word-diff for prose/config diffs.
git diff --no-index <a> <b> diffs arbitrary paths (even outside the repo).
git log <sha> -1 --format=%B prints just the commit message body.