Accidentally staged files you didn’t mean to commit? git restore unstages them without deleting changes. Unstage Specific File: # Staged config.json by mistake git add config.json # Unstage it (keeps changes in working directory) git restore –staged config.json Unstage All Files: git restore –staged . Discard Changes (Careful!): # Unstage AND discard changes git restore […]
Tag: Version Control
Git: Use git bisect to Find Which Commit Introduced a Bug
Bug appeared somewhere in last 100 commits but don’t know where? Git bisect does binary search to find the exact commit. Start Bisect: # Mark current commit as bad git bisect start git bisect bad # Mark last known good commit (e.g., a week ago) git bisect good abc1234 Git Checks Out Middle Commit: # […]
Git: Stash Untracked Files with –include-untracked Flag
Regular git stash only saves tracked files. New files you created get left behind. Include Untracked Files: git stash –include-untracked # Or shorthand: git stash -u Now new files are stashed too! Apply Later: git stash pop Stash Everything (Including Ignored Files): git stash –all Useful before git clean or switching branches with incomplete work.
Git: Undo Last Commit Without Losing Changes (3 Different Scenarios)
Committed too early or to wrong branch? Here’s how to undo commits without losing your work, depending on whether you’ve pushed or not. Scenario 1: Undo Last Commit (Not Pushed Yet) # Keep changes in working directory (most common) git reset –soft HEAD~1 # Now your changes are uncommitted, ready to re-commit # Use case: […]
Speed Up Git Operations 10x by Cleaning Up Bloated Repository History
Is ‘git clone’ taking 10 minutes? Your repository probably has bloated history from large files that were deleted years ago but still exist in Git’s object database. Diagnose the Problem: # Check repository size du -sh .git # If this is >500MB for a code project, you have bloat # Find largest objects in Git […]
Recover Deleted Git Commits Even After Hard Reset (It’s Not Gone)
Accidentally did ‘git reset –hard’ and lost hours of work? Your commits aren’t deleted – they’re just orphaned. Here’s how to find them. The Magic Command – Reflog: git reflog This shows every HEAD movement in your repository, even deleted commits. Output looks like: a1b2c3d HEAD@{0}: reset: moving to HEAD~3 e4f5g6h HEAD@{1}: commit: Added user […]





