Let’s see how these three trees work together?
Git’s typical workflow is to record snapshots of your project in successively better states, by manipulating these three trees. Take a look at this picture:
To get a good visualized understanding, consider this scenario. Say you go into a new directory with a single file in it. Call this v1 of the file. It is indicated in blue. Running git init will create a Git repository with a HEAD reference that points to the unborn master branch
At this point, only the working directory tree has any content. Now we want to commit this file, so we use git add to take content in the working directory and copy it to the index.
Then we run git commit, which takes the contents of the index and saves it as a permanent snapshot, creates a commit object which points to that snapshot, and updates master to point to that commit.
Git – Difference Between HEAD, Working Tree and Index
Git, a popular version control system, helps developers track changes and collaborate on projects efficiently. To use Git effectively, it’s essential to understand its key components: HEAD, the working tree, and the index (also known as the staging area). This article will explain these concepts and highlight their differences, helping you gain a deeper understanding of Git’s functionality.
Git as a version-control-system manages and manipulates three trees in its normal operation:
- HEAD: Last commit snapshot, next parent
- Index: Proposed next commit snapshot
- Working Directory: Sandbox