Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "git status" show way too much untracked files?

Tags:

git

git-status

Answer in the bottom.

I am trying to see the status of my files in the git_test2 directory which contains 3 files named test1.txt, test2.txt and test3.txt.

This is what I typed into Terminal:

cd Desktop
cd git_test2
git status

Everything is good until the git status command. It should show me just 3 untracked files but instead I get this text from the Terminal:

On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

new file:   ../../AndroidStudioProjects/Sunshine/app/src/main/res/layout/list_item_forecast.xml
new file:   ../../Library/Preferences/AndroidStudio1.2/options/fileEditorProviderManager.xml
new file:   ../../Library/Preferences/AndroidStudio1.2/options/git.xml
new file:   ../../Library/Preferences/AndroidStudio1.2/options/other.xml
new file:   ../../Library/Preferences/AndroidStudio1.2/options/runner.layout.xml

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

modified:   ../../AndroidStudioProjects/Sunshine/app/src/main/res/layout/list_item_forecast.xml
modified:   ../../Library/Preferences/AndroidStudio1.2/options/runner.layout.xml

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

../../.CFUserTextEncoding
../../.Rsupport/

and after the last line there are many lines just like the last one (in red color)

I just found out the reason: All I needed to do is git init, now it shows exactly what I expected. Thank you everyone!

like image 335
Ishay Frenkel Avatar asked May 27 '15 07:05

Ishay Frenkel


People also ask

Why are there so many untracked files in git?

All the existing files are "untracked" until you git add them. You probably don't want that. Git stores all its information in a . git directory, so you can get rid of this repository by deleting ~/.

What are untracked files in git status?

Untracked files are those that are in the repo's directory but have not yet been added to the repo's index with git add .


1 Answers

Why are there so many files?

A git repository is just a .git/ directory (folder) located in your project's directory. Like this: myproject/.git/.

If there's no git repository in your current directory, git searches in the parent directory, then in parent's parent and up to top.

As your path was /Users/ishayfrenkel1/Desktop/git_test2, there should be a git repo somewhere in this path.

new file:   ../../Library/Preferences/AndroidStudio1.2/options/git.xml

New files have path at least two levels up from /Library (which is either /Library or /Users/ishayfrenkel1/Library). It means that you have a git repository initiated:

  • either in your home directory: ~/, /Users/<username>/ on OSX or /home/<username> on Linux.
  • or in the root directory, /, the parent of all directories.

How it happened.

Most probably you opened the Terminal and typed git init. Terminal opens in your home directory by default and that's where the new repository was created.

What to do now.

Search for it and delete it. One of the following commands should run without an error. And there it is!

ls /.git
ls ~/.git

Now remove the repository with

rm -rf ~/.git
like image 181
Nick Volynkin Avatar answered Nov 15 '22 22:11

Nick Volynkin