Git untracked files list is wrong

Viewed 26436

Somehow, git got it in its head that I have an untracked file (A directory that has been in my repository for quite some time, ~17 months). At any rate, I can't seem to convince git that this is not an untracked file. Furthermore, I can't re-add the file(s) in question. Any idea how I can fix this?

Example:

➜ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   rosetta_tests/profile/tests/docking/
nothing added to commit but untracked files present (use "git add" to track)

I try to add the directory and re-check the status.

➜ git add rosetta_tests/profile/tests/docking/
➜ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   rosetta_tests/profile/tests/docking/
nothing added to commit but untracked files present (use "git add" to track)

Just to be sure (from the root of my source tree)

➜ git add .
➜ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   rosetta_tests/profile/tests/docking/
nothing added to commit but untracked files present (use "git add" to track)

What is going on here? How can I convince git to fix itself?

EDIT

A few more details:

-The files are not in the .gitignore

-There are three tracked files in the folder in question, so it's not empty

-After even more digging, it seems something like this could arise from changing the case of a tracked folder. This, unfortunately, is not the case (pun!). The folder name has never changed case.

-Contents of the docking directory:

➜ ls -lA rosetta_tests/profile/tests/docking/.
total 16
-rw-r--r--  1 tim  staff  2209 Jul 17 10:47 command
-rw-r--r--  1 tim  staff   260 Jul 17 10:47 flags
drwxr-xr-x  3 tim  staff   102 Jul 17 10:47 input
8 Answers

Same issue i got and i solved

git clean -f -n

I had important untracked files and couldn't just run git clean -f as some answers suggest.

I try to add the directory and re-check the status.

➜ git add rosetta_tests/profile/tests/docking/

And it seems that adding a whole directory does not trigger a file recheck.

So I tried adding specifically one of the supposedly untracked files and it worked:

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

        important.txt
        foo/foo.java
        foo/bar.java
        foo/baz.java
        foo/qux.java

nothing added to commit but untracked files present (use "git add" to track)

$ git add -- foo/foo.java
fatal: pathspec 'foo/foo.java' did not match any files

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

        important.txt

nothing added to commit but untracked files present (use "git add" to track)

This error popped up for me when git add failed due to a file name being too long in a sub directory. (in my case, something in node_modules)

In this case, adding a .gitignore file with content of * to the node_modules folder allowed git add to run to completion.

So, pay attention to the command output of git add . (or -A or --all) and make sure it is not stopping prematurely due to an error. All of my "untracked" files and folders were added successfully once the proper .gitignore was applied and I was able to commit and push my changes.

Recreate the file or directory

mkdir -p rosetta_tests/profile/tests/docking/

And then remove it again.

rm -rf rosetta_tests/profile/tests/docking/
Related