How Git keeps every version of your project without filling your disk
The Git staging area: why you pick before you commit
Git makes you type git add before every commit, and it is not a wasted step: it lets one commit keep the work that is ready and leave the half-done rest out.
-
1
Today your folder holds two changes: the score fix in game.js is ready, and the night sky you started in index.html is half done. You want to keep the fix and leave the sky out.
-
2
Here is the trick: a commit is not taken from your folder. Between the folder and the repository, Git keeps the staging area, which holds the next snapshot file by file, and a commit takes exactly what is there.
-
3
So you run
git addon game.js alone, and the new game.js is copied into the staging area. The index.html there is still the one from the last commit, with no sky. -
4
Then
git committakes the staging area as it is: the score fix goes in, and the half-made sky stays in your folder, still yours to finish. -
5
Commit after commit, you pick what goes in. Five commits wait in the repository now, and so far nothing you have seen tells Git which one came first.
-
Quick check
You change a file and run
git add. Then you change the same file again, and you commit.Show the answer
The one from
git add. The staging area holds the file as it was when you added it, and the later change stays in your folder until you add it again. -
Go further
The real names around the staging area.