Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between a tracked and a staged file?

Tags:

git

I've just started reading the book "Pro Git" by S. Chacon and B. Straub. On Chapter 2, in the Section Recording Changes to the Repository you'll find this statement:

Remember that each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged.

From this, I got the impression that the set of tracked files may be bigger than the set of staged files. But at the same time when I look at this link, I can see the statement below which seems to contradict what's written in the book:

To tell Git to start tracking changes made to octocat.txt, we first need to add it to the staging area by using git add.

which appears to say that every staged file is a tracked file and vice-versa.

What am I missing?

like image 937
John Kalane Avatar asked May 10 '16 14:05

John Kalane


2 Answers

They do not contradict.
You are right, every staged file is a tracked file, but you are wrong, not every tracked file is staged.
In the staging area, you collect the changes that make up the next commit.
So if you modify one file and add its changes to the index, that one file is staged, while all other already commited files are also tracked files.

like image 104
Vampire Avatar answered Oct 12 '22 03:10

Vampire


Every staged file is tracked, but not vice-versa. A tracked file in Git simply means that is "on the radar" of Git, in other words Git follows the versioning of the file. To understand better what a tracked file is we can consider what an untracked file is. An untracked file on your local system is not versioned, and therefore is not present on the remote Git repository. To Git, an untracked file does not really exist, though to you it does exist, at least on your local file system.

The Git staging area is a place where Git actually performs most of its actions. For example, if you want to commit your work, you need to stage the files which you intend to be part of that commit. To understand better what a staged file is, we can consider the difference in behavior between a staged file and a non-staged, but tracked, file. If you perform a commit, it will consist of all the changes (diffs) from the staged files, but unstaged tracked files will be ignored during this operation.

like image 36
Tim Biegeleisen Avatar answered Oct 12 '22 02:10

Tim Biegeleisen