git add
Yesterday, I was trying to explain git add
and git commit
to someone, and hit upon these very clear ways (IMHO) of explaining them:
git add
adds changes to the next commitgit commit
saves anyadd
ed changes to the (local) repository
Why is this particularly clear? It eliminates any notion of “tracked files”.1 You use add
whenever you want to record changes in your version history, whether files are new or not.
For people who prefer the classical workflow of “commit every modification to a tracked file”, there’s git commit -a
. I used to think of -a
as “all”, but now I think of it as “add”. I’ve shot myself in the foot a couple of times with this classic style (committing a file that’s not part of the current logical change), so I’ve mostly given it up when working in a Git/Mercurial repo. (Not that I haven’t left a file out of a change using the two-stage commit.)
Of course, my usual Git workflow now is through TextMate, which shows you all modified and untracked files in the current directory and allows you to check them off when you say “Commit”.
-
For that matter, it eliminates any notion of “files” at all, since git allows staging parts of a file (“hunks”) for a commit. ↩︎