staging and commits

staging and commits

how to stage changes and write commits that actually make sense

staging and commits

copy
git add .

stages everything in the current directory. convenient but be careful — use git status first so you don't accidentally add junk.

copy
git add -p

interactive staging. goes through each diff hunk and asks if you want to stage it. good when you've changed a bunch of stuff and want clean, focused commits instead of one giant blob.

copy
git commit -m "your message here"

basic commit. write messages that describe why, not just what.

copy
git commit --amend

rewrites the last commit. use it to fix a typo in your message or add a file you forgot. don't amend after you've pushed unless you're okay with force-pushing.

copy
git stash

shelves your current changes so you can switch context. nothing gets committed, just saved off to the side.

copy
git stash pop

brings those changes back. if you have multiple stashes, git stash list shows them and git stash pop stash@{1} lets you pick one.