ant2009
ant2009

Reputation: 22696

Cannot see new files added to my git working directory

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,

Upvotes: 66

Views: 142018

Answers (12)

Wilt
Wilt

Reputation: 44422

Try to remove the index.lock file (if there is one)

I had exactly the same issue in my Intellij when trying to add some Unversioned Files in my commit window using the Add to VCS from the context menu (right click). This action didn't do anything and no errors thrown either.

When I tried to add the file using the command line as follows:

git add source.c

I got a fatal:

fatal: Unable to create 'C:/path/to/repository/.git/index.lock': File exists.

Removing the lock file (as also mentioned in the answer here) resolved the issue and I was able to add files again like normally.

Apparently the empty lock file was like a leftover from some previous failed action and it was locking the index state preventing adding any new files.

Upvotes: 1

Antoine De Groote
Antoine De Groote

Reputation: 87

I had the same problem. Drove me nuts. Finally found out that I had a .gitignore file in my user directory (C:/Users/user/.gitignore), which was taken into account additionally to the project .gitignore. After deleting that file in my user directory, everything worked as expected.

Upvotes: 0

Jorge Borges
Jorge Borges

Reputation: 21

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.

Upvotes: 1

Black
Black

Reputation: 20382

It is most likely ignored by your .gitignore file.

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

Upvotes: 16

gauravsngarg
gauravsngarg

Reputation: 666

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.

Upvotes: 3

Diorgo
Diorgo

Reputation: 41

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.

Upvotes: 4

Vinay Vemula
Vinay Vemula

Reputation: 3995

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

Upvotes: 18

Kfir Ilani
Kfir Ilani

Reputation: 51

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

Upvotes: 5

HappyCoder
HappyCoder

Reputation: 6155

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.

Upvotes: 2

Richard Hansen
Richard Hansen

Reputation: 54273

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.

Upvotes: 69

hammar
hammar

Reputation: 139930

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.

Upvotes: 64

Jani Hartikainen
Jani Hartikainen

Reputation: 43273

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

Upvotes: 26

Related Questions