60

git version 1.7.4.1

I am using git on Ubuntu.

I have copied some files from another directory to my git working directory. Normally would appear under Untracked files. However, they do not appear. So I cannot add them.

When I do a git status the new files are not shown.

I tried to add them by doing git add source.c then tried git status. The file was not show.

So I opened the file and did a save as as the same name. git status still failed to see the file.

I have done a git ls-files and the new files are shown ok.

I have checked the file permissions and they are the same as all the current files in my git directory.

I have never had this problem before.

Many thanks for any suggestions,

ant2009
  • 27,094
  • 154
  • 411
  • 609

10 Answers10

66

If git ls-files shows source.c, then it must already be in the index. This means that it is already tracked, and possibly already committed. If source.c isn't showing up in git status at all, then the file must have been committed.

Try modifying the file to see if it shows up as modified in git status. To really convince yourself that the file is checked in, run git cat-file -p HEAD:source.c to see the contents of the checked-in file (see git help revisions for documentation about the HEAD:source.c syntax).

In addition, one or more of the following may be true:

  • The file has been modified, but the 'assume unchanged' bit is set in the index. Take a look at the output of git ls-files -v source.c. If the first column is a lower-case letter, then the 'assume unchanged' bit is set. This will prevent any changes from showing up in git status. You can turn off the 'assume unchanged' bit by running git update-index --no-assume-unchanged source.c.
  • The file has been modified, but the 'skip-worktree' bit is set in the index. If the first column of the output of git ls-files -v source.c is s or S then the 'skip-worktree' bit is set. You can turn off the 'skip-worktree' bit by running git update-index --no-skip-worktree source.c.
  • Your index is corrupt. Try deleting .git/index (Git will recreate it as necessary).
  • Filesystem issues are preventing stat() from working properly. Try running git update-index --really-refresh. If your working directory is on a network drive (NFS, sshfs, etc.) try moving your repository to a local drive.
Richard Hansen
  • 51,690
  • 20
  • 90
  • 97
  • 1
    I have the same issue. The first two points didn't apply to me because the first column displayed `H`. I deleted `.git/index`; `git status` now shows tracked files, but they all show up as deleted even though all the files exist. I tried `git update-index --really-refresh` to no avail. – Will Sewell Mar 05 '13 at 23:37
  • 1
    I used `git reset`, and now `git status` goes back to not displaying my tracked files -- the original problem. – Will Sewell Mar 05 '13 at 23:50
  • 1
    @Fractal: If `git status` doesn't show the files, but `git ls-files -v` shows `H`, then the file has been committed and has not been modified since it has been committed. This is normal -- `git status` only shows deviations from normal (untracked files, files that have been modified since staged/committed, files that have been staged but not yet committed). – Richard Hansen Mar 06 '13 at 17:01
  • @RichardHansen i have similar problem, it shows H and if i modify the file now after committing changes, it doesn't show up in status. Any idea why? – blganesh101 Apr 24 '14 at 15:24
  • 1
    @blganesh101: You may want to file a new question because there are a lot of details I'd need, e.g.: What is the output of `git status` before you modify the file? What is the output of `git ls-files -v ` after you modify the file? What version of Git are you using? What operating system? What filesystem? Does deleting `.git/index` change anything? Does `git update-index --really-refresh ` change anything? – Richard Hansen Apr 24 '14 at 18:27
  • really the people vote for "Try deleting .git/index" that is crazy. the most logical action is try to check the ignore rules, check other responses in this post https://stackoverflow.com/a/34996761/2062838 – tierrarara Aug 10 '18 at 18:16
  • On Windows, I had renamed a file with the same name but different case (don't do this). The file was listed by `git ls-files` but somehow not in the repository. Explicitly deleting and re-adding it in separate commits fixed it. This is almost certainly related to your last point about `stat()`. – Cameron Apr 18 '19 at 13:15
57

It's hard to tell what's wrong from the information given, however as a workaround you can try git add -f filename.c. This will add the file even if it would otherwise be ignored.

hammar
  • 138,522
  • 17
  • 304
  • 385
26

This is really a poke in the dark, but I've occasionally had similar issues and it has been a case of one of these:

  • You have a rule in .gitignore which ignores the files
  • You have a .git dir in one of the directories you've copied
Jani Hartikainen
  • 42,745
  • 10
  • 68
  • 86
  • There is nothing in the .gitignore. The files are *.c source files. And I have many of them that I am working on that show ok. I just copied the files and nothing else. Thanks. – ant2009 Jul 08 '11 at 04:52
  • 4
    Note that `.git/info/exclude` and the file referred to by the `core.excludesfile` config variable can also contain ignore rules. However, I believe that Git prints a friendly "your file wasn't added because it was ignored" message when running `git add` if it's an ignore problem, which means it's probably not an ignore problem. – Richard Hansen Jul 15 '11 at 17:39
  • 2
    +1 the `.gitignore` rule tripped me up. I copied a file into a the build directory, so it worked correctly when built, but didn't appear anywhere in the status. – Patrick M Aug 22 '14 at 21:28
  • Thanks this was useful! – bmustata Aug 27 '15 at 07:06
  • 1
    It turned out to the `.gitignore` for me too. So, do you have to update `.gitignore` of the branch it isn't ignored in? That's how I solved it for now. – aashah7 Jun 12 '17 at 20:51
  • I had a .gitignore file in the directory that was not showing. Removing this solved the issue – pusle Nov 30 '21 at 09:23
18

I was create a package ending with image.gen which had a corresponding directory ending with image/gen. And there was a .gitignore entry, that was specific to Android gen/.

This was leading to file not getting added to git/ showing in git status.

Check below, it helped me solve the issue.


Use git check-ignore command to debug your gitignore file (exclude files).

In example:

$ git check-ignore -v config.php
.gitignore:2:src    config.php

The above output details about the matching pattern (if any) for each given pathname (including line).

So maybe your file extension is not ignored, but the whole directory.

The returned format is:

<source> <COLON> <linenum> <COLON> <pattern> <HT> <pathname>

Or use the following command to print your .gitignore in user and repo folder:

cat ~/.gitignore $(git rev-parse --show-toplevel)/.gitignore $(git rev-parse --show-toplevel)/.git/info/exclude

Alternatively use git add -f which allows adding otherwise ignored files.

See: man gitignore, man git-check-ignore for more details.

https://stackoverflow.com/a/28918909/4082503

Community
  • 1
  • 1
Vinay Vemula
  • 3,855
  • 1
  • 21
  • 24
13

It is most likely ignored by your .gitignore file.

Call git status --ignored and see if your file appears.

Black
  • 18,150
  • 39
  • 158
  • 271
5

It could be that 3rd party application updated your "gitignore_global.txt" file (~/.gitignore_global on Linux / OS X). It happned to me. I installed "Source tree" and notice after that git does not tracked new files. It found that "Source tree" changed "gitignore_global.txt" file and add it several extension to not monitor. Try to locate this file and see if there file's extensions that shuold not be there

MikeMB
  • 20,029
  • 9
  • 57
  • 102
Kfir Ilani
  • 51
  • 1
  • 2
4

I had the same problem. Git did not show any new files added to my project.

Mine was caused by the following: Somehow my project’s main folder got added to the “Repository-specific ignore list” (that’s what it’s called in SourceTree). This is the “.gitignore” file in the root of my project’s main folder.

It worked after I deleted the folder name in the “.gitignore” file.

Diorgo
  • 41
  • 1
3

Android Repo - Same problem i faced- Corrected as below

Somehow i added "/app" in .gitignore file. Now after deleting "/app" it worked.

Please check your .gitignore.

gauravsngarg
  • 606
  • 5
  • 11
2

Deleting the .git/index file did the trick. Quite a frustrating error which I seem to come into contact when I clone skeleton modules into my zf2 project.

HappyCoder
  • 5,985
  • 6
  • 42
  • 73
1

git config --global status.showuntrackedfiles all - Resolution for an old case. You can use git status untracked-files=all in the terminal, but it is longer if set --global, the code above, it will only need,git status for files appear in the untracked location.