Interactive rebase last 5 commits
Open the last 5 commits in the interactive rebase todo list.
git rebase -i HEAD~5Interactive rebase is the main advanced tool for reordering, squashing, editing, or dropping commits before sharing them.
Advanced Git commands and workflows for rewriting history, recovering commits, debugging regressions, working with multiple trees, and maintaining repositories.
Rewrite commit history safely and intentionally.
Open the last 5 commits in the interactive rebase todo list.
git rebase -i HEAD~5Interactive rebase is the main advanced tool for reordering, squashing, editing, or dropping commits before sharing them.
Replace the most recent commit using the current staged changes.
git commit --amend --no-editUseful when you forgot to add files or want to correct the content of the last commit while keeping its message.
Move a branch from one base commit or branch to another.
git rebase --onto main old-base feature`--onto` is the advanced rebase form for transplanting a branch or a subset of commits onto a different base.
Create a new history containing only one subdirectory.
git filter-branch --subdirectory-filter path/to/subdir -- --allOlder but still encountered approach for history rewriting. For large or modern repos, many teams prefer `git filter-repo` externally.
Rebase while preserving merge topology.
git rebase -i --rebase-merges mainUseful when you need the benefits of interactive rebase but your feature branch already contains meaningful merge structure.
Recover lost work and pinpoint regressions.
Inspect branch and HEAD movements with readable times.
git reflog --date=localReflog is one of the most important recovery tools in Git because it records local reference updates even after history rewriting.
Begin a binary search to find the commit that introduced a bug.
git bisect start && git bisect bad && git bisect good <known_good_commit>`git bisect` uses binary search over commit history to isolate the commit that changed a known property, commonly a bug introduction.
git show ORIG_HEADHelpful after merge, pull, reset, and rebase operations when you need to inspect where HEAD was before the change.
Verify object connectivity and repository health.
git fsck --fullUseful when investigating possible repository corruption or dangling objects after recovery operations.
Stash, worktree, clean, sparse workflows, and conflict reuse.
Check out another branch in a separate directory without cloning again.
git worktree add ../feature feature-branchWorktrees are excellent for parallel branch work, hotfixes, and avoiding branch switching in a single working directory.
Save tracked and untracked work temporarily.
git stash push -u -m "WIP before rebase"Use `-u` when your temporary work includes new files that are not yet tracked.
Dry-run a repository cleanup before deleting anything.
git clean -ndxAlways preview with `-n` first. `-x` includes ignored files, which can be destructive in build directories.
Inspect recorded conflict-resolution reuse state.
git rerere status`rerere` can save time during repeated conflict resolution in long-lived branches or repeated rebases.
Notes, submodules, range selection, and patch-style workflows.
Apply commit changes into the index and working tree first.
git cherry-pick -n <start_commit>^..<end_commit>Useful when you want to combine multiple picked commits into one local commit or inspect them before committing.
Populate nested submodules after clone or after config changes.
git submodule update --init --recursiveCommon recovery and onboarding command when a repository uses submodules and nested dependencies.
git notes add -m "Reviewed by security team" <commit_sha>Git notes let you annotate objects while preserving their original identity and hash.
Review how a patch series changed across rebases.
git range-diff main...feature-v1 main...feature-v2Especially useful in advanced review workflows after interactive rebase or when patch series evolve.