Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are tracked files and untracked files in the context of Git?

I'm new to Git. I wish to know what are tracked and untracked files? I read "Pro Git", but still couldn't quite understand.

Can someone explain to me the difference between the two by providing an example?

like image 738
Nayan Soni Avatar asked Mar 12 '12 08:03

Nayan Soni


People also ask

What does it mean when a file is untracked?

What Are Untracked Files? Untracked files are the ones still not versioned—”tracked”—by Git. This is the state of new files you add to your repository. That basically means Git is aware the file exists, but still hasn't saved it in its internal database.

How do I keep my git files untracked?

You have to add the untracked files of the repository by using the “git add” command and run the “git stash” command to save the untracked file and clean the current directory for working by removing the untracked file from the repository folder.

How do I add a tracked file to git?

When you start a new repository, you typically want to add all existing files so that your changes will all be tracked from that point forward. So, the first command you'll typically type is "git add ." (the "." means, this directory. So, it will add everything in this directory.) I'll type "git add ." and press Enter.


1 Answers

A file is tracked if it is under version control.

As a small example, a C++ project would have

Makefile main.cpp interface.hpp worker.cpp 

as source files; you'd put these under version control. During build,

main.o worker.o myapp 

are generated; these do not belong under version control, so you do not use git add on them. They remain untracked, because git does not care what happens to them. Until you add them to .gitignore (the .o files are ignored by default), git does not known whether you want to add or ignore them, so it displays them with the git status command until you make a decision.

Whether a file is tracked or not also depends on the version -- suppose you autogenerate worker.cpp and remove it from version control at a later version. The file is now untracked in that version. When you go back to a version where the file was still under version control, git will refuse to overwrite that file during checkout.

like image 197
Simon Richter Avatar answered Oct 02 '22 05:10

Simon Richter