Question

In the diagram shown on the git-scm page, Recording Changes to a Repository, it shows that when an untracked file is added, it moves to the unmodified state.

enter image description here

Is this correct? If I run $ git add myFile then $ git status, it shows that myFile is ready to be committed, which (from my beginner's perspective) looks unintuitive when looking at the diagram on that page.

Is the diagram incorrect, incomplete, or is my understanding of the diagram incorrect? If the latter, please could someone explain what is meant.

Was it helpful?

Solution

When you git add a new previously untracked file, it is staged immediately (the blue stage in the image). The diagram is misleading in that regard, but the text on that page says as much under the paragraph Tracking New Files.

OTHER TIPS

The graphic is misleading because it does not clearly call out the difference between a file and a version of the same file.

When you git add a file, you are adding the current version of it in your working directory to the Staging Area. The current version is now considered Staged and ready to commit. Because your working directory file contents are the same as those of the Staged version, the file is considered Unmodified. If you were to commit at this moment, the version that gets checked into the repo is the Staged version which also happens to match what the file looks like in your working directory.

But, suppose that instead of committing immediately after adding the file, you were to make some more changes to the file in your working directory. Now, you actually kind-of have two versions of the file: the Staged version from earlier, and, now the Modified version in your working directory. If you were to commit at this moment, the earlier Staged version gets checked in, which is different from what's in your working directory.

The answer to you question is yes. When you stage untracked file it becomes staged, not unmodified.

For me, the most difficult problem with this diagram, was the that it makes no sense to categorize files as:

  • untracked
  • unmodified
  • modified
  • staged

The correct categories, in my opinion, are:

  • untracked
  • unmodified
  • unstaged
  • staged

correct categories for state of the file

The important adjectives are marked with pink colour. The gray ones are redundant. You don't have to say: "the file is tracked, modified and staged". It is enough to say "the file is staged", as every staged file is modified and tracked.

Once you realize it, it is easy to understand, that untracked file can be only transferred into staged state. This is done by:

git add [filename]

There are no commands to make conversions:

  • untracked file => unmodified file
  • untracked file => unstaged file
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top