8. Three places: your files, the tray, the last commit
Git moves content between the working tree, the index and HEAD: add copies a file into the index (staging it), commit photographs the index and moves the branch.

8. Three places: your files, the tray, the last commit

Git moves content between the working tree, the index and HEAD: add copies a file into the index (staging it), commit photographs the index and moves the branch.

The index is the thing most people never form a picture of, and without it add, commit, diff and reset all look arbitrary.

Git works with three places. Your files on disk. The index. And the last commit, the one under HEAD.

The index is the proposed next commit. Git also calls it the staging area. A tray where you lay out exactly what the next photo will hold. Putting a file there is staging it.

You edit a file. Only your copy changes. The tray still holds the old version.

git add copies the file into the tray. Now the tray and your copy agree. The last commit does not.

git commit takes the photo of the tray, not of your disk. Then it moves the branch to it. Now all three agree.

Check yourself. You edit a file after adding it, then commit. Which version is in the commit?

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime