Git: Rebase, bisect & advanced history
12 Git commands: Rebase, bisect & advanced history. Click a command to see what each part does.
Git: Rebase, bisect & advanced historyIndex
Rebase, bisect & advanced history12
git rebase -i HEAD~<n>Clean up your last commits before a PRCautionWhat each part does
rebase -iinteractive: reorder, squash (s), fixup (f), reword (r) or drop commitsHEAD~<n>the last n commits
Tip Rewrites history: only for commits not yet shared, or push with --force-with-lease.
git fetch origin && git rebase origin/mainRebase your branch on the latest mainCautionWhat each part does
git fetch originget the newest maingit rebase origin/mainreplay your commits on top of it
git rebase --continue; git rebase --abort; git merge --abortContinue, skip or abort a rebase / mergeWhat each part does
--continueafter fixing conflicts and git addrebase --abortgo back to before the rebasemerge --abortcancel a conflicted merge
git commit --fixup <commit> && git rebase -i --autosquash <commit>~1Squash a fix into an earlier commit automaticallyCautionWhat each part does
commit --fixup <commit>commit marked fixup! for that commitrebase -i --autosquashmoves and squashes it into place
git bisect start <bad> <good>; git bisect good; git bisect bad; git bisect resetFind the commit that introduced a bugWhat each part does
bisect start <bad> <good>binary search between a bad commit (e.g. HEAD) and a known good onebisect good / badmark each checked-out commit after testingbisect resetfinish and return to your branch
Tip git bisect run <test-script> automates it.
git log --oneline main..<branch>Commits on a branch that aren't on mainWhat each part does
main..<branch>reachable from branch but not from main
git diff main...<branch> --statCompare two branchesWhat each part does
main...<branch>changes on branch since it split from main (three dots)--statfiles and line counts only
git shortlog -sn --no-mergesWho committed how muchWhat each part does
shortlog -s -ncommit count per author, sorted--no-mergesskip merge commits
git grep -n '<text>' <commit-or-branch>Search the code in any commitWhat each part does
git grep -nfast search of tracked files with line numbers<commit-or-branch>search that version instead of the working tree
git restore --source=<commit> -- <file>Restore a file from another commit or branchCautionWhat each part does
--source=<commit>take the file's content from that commit-- <file>only that path
git describe --tags --alwaysDescribe the current version from tagsWhat each part does
describe --tagsnearest tag + commits since + short SHA, e.g. v1.4.0-3-g4f2a9c1--alwaysfall back to the SHA if no tag
git filter-repo --invert-paths --path <file>Remove a file from all history (leaked secret)DestructiveWhat each part does
git filter-reporewrite the whole history (separate tool, replaces filter-branch)--invert-paths --path <file>drop that file everywhere
Tip Rotate the secret first; everyone must re-clone after the force push.
Nothing matches.
My DevOps Playbook by Angelo John Calleja