File status lifecycle

In a Git repository, files pass through some different states. When you first create a file in the working tree, Git notices it and tells you there's a new untracked file; let's try to create a new file.txt in our grocery repository and see the output of git status:

[23] ~/grocery (master)
$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

file.txt

nothing added to commit but untracked files present (use "git add" to track)

As you can see, Git explicitly says that there's an untracked file; an untracked file is basically a new file Git has never seen before.

When you add it, it becomes a tracked file.

If you commit the file, then it goes in an unmodified state; this means Git knows it, and the current version of the file in the working tree is the same as the one in the HEAD commit.

If you make some changes, the file goes to a modified state.

Adding a modified file to the staging area makes it a staged file.

The following figure summarizes these states:

Knowing this terminology is important to better understand Git messages, and it helps me and you to go smoothly while talking about files in a Git repository.

Now it's time to go a little bit deep with git reset and git checkout commands.

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

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