The three areas of Git

In Git, we work at three different levels:

  • The working tree (or working directory)
  • The staging area (or index, or cache)
  • The HEAD commit (or the last commit or tip commit on the current branch)

When we modify a file, we are doing it at working tree level; when we do a git add, we are actually copying the changes from the working tree to the staging area. At the end, when we do a git commit, we finally move the changes from the staging area to a brand new commit, referenced by HEAD, which will become part of our repository history: this is what I mean with the HEAD commit.

The following figure draws those three areas:

We can move changes between these areas forward, from the working tree to the HEAD commit, but we can even go backward, undoing changes if we like.

We already know how to go forward using git add then git commit; let's take a look at the commands to go backward.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.175.182