See what changed, unstaged and staged
git diff
git diff --staged
The first shows edits you haven’t staged. The second shows what the next commit will contain.
The git commands for a normal day, from checking what changed to undoing a commit, stashing, rebasing, and finding the commit that broke it.
git diff
git diff --staged
The first shows edits you haven’t staged. The second shows what the next commit will contain.
git log -S "useLegacyAuth" --oneline
-S finds the commits that added or removed the string. -G takes a regex and matches any changed line.
git blame -L 10,20 src/app.ts
git log -L 10,20:src/app.ts walks the history of the same range.
git status --ignored
git reset --soft HEAD~1
--soft leaves the changes staged, --mixed unstages them, --hard throws them away.
git restore --staged src/app.ts
Without --staged it discards the working-tree changes instead, and there is no undo for that.
git commit --amend
Only on a commit you haven’t pushed. Amending rewrites it, and anyone who already has the old one gets a conflict.
git switch -c feature/login
git switch - goes back to the branch you came from.
git fetch origin
git rebase origin/main
Rewrites your branch’s commits on top of main. Never on a branch someone else has checked out.
git branch -d feature/login
-d refuses if the branch isn’t merged, -D deletes anyway. The remote copy goes with git push origin --delete feature/login.
git stash push -u -m "wip: login form"
Without -u untracked files stay behind. git stash pop brings the stash back and drops it.
git bisect start
git bisect bad
git bisect good v1.4
Git checks out the midpoint. Mark each one good or bad until it names the commit, then git bisect reset.