david.colais
david.colais

Reputation: 619

GIT not tracking files

I have setup GIT on AIX 6.1 and am facing problems.

The sequence of steps I followed are as shown:

  1. I create a folder.
  2. Go into the folder and initialise the non-bare repository
  3. Initialise the username and user email
  4. Create a file named index.html with some data in the file.
  5. Create a subfolder named newfolder
  6. Go into the newly created folder.
  7. Create a new file named index-2.html with some data in it.

After performing all the steps above and give the git status command I'm getting the foll result:

# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       ../index.html
#       ./

I understand that index.html in the above directory is getting displayed but why doesent index-2.html not getting displayed which is in the current directory.

The file index-2.html should also get tracked right.

Upvotes: 6

Views: 40159

Answers (2)

martiert
martiert

Reputation: 741

It is tracking the folder ./ which means the current folder. git doesn't (correct me if I'm wrong), care about subfolders at all. Meaning if you have a repository with the folder foo, which is already in the repository. You add a subfolder bar in foo, and create a file foobar.txt in foo/bar. Then you will only get:

# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       ./bar

Which means that if you had done cd .. before your git status command, you would get:

# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       index.html
#       newfolder

even though you have a file inside.

The reason for this is that git tracks content, not files. Since index2.html actually is a content of the folder newfolder, and you are not tracking newfolder, git doesn't know that index2.html exists.

Upvotes: 3

poke
poke

Reputation: 388113

The output shows two things that are currently untracked:

  • ../index.html – the index.html file in the parent folder
  • ./ – the current folder, including all its contents

So it does detect that you have an untracked file, but because it does know nothing about its folder as well, it just shows the folder to accumulate all its content.

If you add your files and make Git track them, they will show up correctly:

git add index-2.html
git add ../index.html

Upvotes: 10

Related Questions