Lesson 2 · Unit 01
Three trees
Working directory, index and HEAD
What you practise
- Working directory, index (staging area) and HEAD
git addandgit commitmove content between them- Reading
git statusandgit diffvsgit diff --staged
Try a question from this lesson
Pick one
The file is edited again after git add. Which version does the commit hold? (git show HEAD:f.txt prints the committed copy.)
git init -q
echo v1 > f.txt
git add f.txt
echo v2 > f.txt
git commit -q -m save
git show HEAD:f.txtCorrect answer
v1
Why
git add copies the file as it is at that moment into a staging area, and git commit snapshots the staging area, not your folder. The v2 edit exists only in your folder until you add it again.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Three places
Git keeps three versions of your project. The working directory is the files you edit. The index, or staging area, is the draft of the next commit. HEAD is the last commit.
git add copies a file from the working directory into the index. git commit turns the whole index into a new commit.
working directory (files you edit)
| git add
v
index (next commit's draft)
| git commit
v
HEAD (last commit)11 more exercises in the app
- 3× type the answer
- 3× multiple choice
- 1× fill the blanks
- 2× true or false
- 1× order the lines
- 1× match the pairs
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.