There's no Tree in Working Tree, and no Area in Staging Area
This is my take on the Working Tree and the Staging Area. I think it would be less confusing if they were called Working Area and Staging Tree respectively instead.
Working Tree
The Working Tree is but the physical directory on your disk where your project is located. It contains the current "version" of all your files and sub-directories. By "version", I mean the actual contents of each file as you would see them if you open a file in, say, a text editor.
As far as I know, no hashes are generated or maintained on the files in thw Working Tree. So it is not really a Git tree per se. I would prefer to call it the Working Area.
However, maybe the inventors of Git do not want us to think of the Working Tree as an object, but as a state. Thus the Working Tree shows the current changed files in the project directory on disk, just changed and not added to the Staging Area.
Anyway, git status
does not show the whole Working Tree. It lists only new files, and those files which are different from the version in the Staging Area.
Staging Area
The Staging Area is a list of Git file blobs. It is not a genuine Git tree object. When your Git project is first created, the Staging Area reflects the latest state of the Repo. So if you had initialized a Git folder from scratch, the Staging Area would be empty. If you had freshly cloned a project, the Staging Area would be the same as the Repo. If you have just committed all your staged files, the Staging Area would also be the same as the Repo.
The Staging Area is less of a storage area where you move files in and out, but more of a list of files. If a file has been changed in the Working Tree and has not be git add
, the blob in the Staging Area is tagged with a C, for Changed. When it is git add
ed, its blob object is updated in the Staging Area list. The Staging Area thus can be more accurately described as a listing of changed files, as compared to the Repo. I would prefer to call it the Staging Tree.
git status
does not show the whole listing of the Staging Area. It shows only those that have been git add
ed and are ready for commit.
Repo
The Repo is the place where every commit is maintained.
Demonstration
Use git ls-files -moscdt
to see all the files in the Working Tree and the Staging Area.
? newfile.txt
? src/newfile.js
H 100644 c0b9ad1d30878eecd4ce49e1db40ac59f9668536 0 README.md
H 100644 fabf7fc4cbfd9fc5bebeae2ddf7db473bf867ed3 0 file1.txt
H 100644 25b690689b298649c027af668c051282a96eed6c 0 file2.txt
C 100644 25b690689b298649c027af668c051282a96eed6c 0 file2.txt
With the -s
option, Working Tree shows new untracked files as path/file names, but files in the Staging Area are shown with their Git blob hashes.
For a modified file in the Working Tree that has not been added to the Staging Area, ie the Working Tree version is different from the Staging Area version, it is shown as a blob with tag C (for Changed).
A newly added untracked file is tagged as others or ?.
Comments
Post a Comment