Note This is the CLI equivalent of a graphical Git viewer. --all shows all branches, --decorate labels commits with branch/tag names. A great alias candidate: git config --global alias.lg 'log --oneline --graph --all --decorate'
Note Shows the commit, author, date, and line content for each line. Use -L to limit to a range. Blame doesn't mean assigning fault — it's just finding who last changed a line and why.
who changed lineblameline historywho wrote thisfind author of code
Binary Search for Bug Introduction
syntax
git bisect start
git bisect bad [commit]
git bisect good <commit>
example
git bisect start
git bisect bad # Current commit is brokengit bisect good v1.0.0# This tag was working# Git checks out a middle commit, you test it:# If it's good:git bisect good
# If it's bad:git bisect bad
# Repeat until Git finds the first bad commitgit bisect reset # Return to original branch
output
Bisecting: 8 revisions left to test after this (roughly 3 steps)
a1b2c3d is the first bad commit
Note Bisect uses binary search to find the exact commit that introduced a bug. For N commits, it takes at most log2(N) steps. You can automate it with: git bisect run <test-script>
find bug commitbisectwhen did bug appearbinary search commitstrack down regression
View Reference Log (Recovery Tool)
syntax
git reflog [branch]
example
git reflog
git reflog show feature/payments
output
a1b2c3d HEAD@{0}: commit: Add auth endpoint
f4e5d6c HEAD@{1}: reset: moving to HEAD~1
9g8h7i6 HEAD@{2}: commit: Broken attempt
b3c4d5e HEAD@{3}: checkout: moving from feature to main
Note The reflog records every time HEAD moves. It's your safety net — even after a hard reset or accidental branch deletion, you can find the commit hash here and recover with: git reset --hard HEAD@{n}. Entries expire after ~90 days.
reflogrecover lost commitundo resetfind deleted branchsafety netrecovery
# All differences between the two branches:git diff main..feature/payments
# Only changes introduced in feature/payments since it diverged from main:git diff main...feature/payments
Note Two dots (..) shows the full diff between branch tips. Three dots (...) shows only what changed in the right branch since the common ancestor. Three dots is usually what you want for reviewing a feature branch.
diff branchescompare branchesbranch differenceswhat changed on branch
Cherry-Pick a Commit
syntax
git cherry-pick <commit> [<commit2> ...]
example
gitswitch main
git cherry-pick a1b2c3d
# Cherry-pick a range:git cherry-pick d4e5f6g..h7i8j9k
Note Creates a NEW commit with the same changes (but different hash). Useful for applying a bugfix from one branch to another without merging the whole branch. If there's a conflict, resolve it and run git cherry-pick --continue.
cherry pickcopy commit to branchapply specific commitpick one commit
# Find commits mentioning 'authentication':git log --grep="authentication" --oneline# Find commits where 'validateToken' was added or removed:git log -S "validateToken"--oneline# Regex search in diffs:git log -G "api.*endpoint"--oneline
output
a1b2c3d Add user authentication endpoint
f4e5d6c Refactor authentication middleware
Note -S (pickaxe) finds commits where the number of occurrences of a string changed. -G finds commits where the diff matches a regex. --grep searches commit messages only.
search commitsfind commit by messagesearch code changespickaxegrep commits