Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot see new files added to my git working directory

Tags:

git

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,

like image 478
ant2009 Avatar asked Jul 08 '11 04:07

ant2009


People also ask

Why are new files not showing up in git status?

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.

How do I add files to a git working directory?

To add and commit files to a Git repository Create your new files or edit existing files in your local project directory. Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed.

How do I see changes after git add?

The first approach, using the regular rm command outside of Git, will be viewed by Git as a change to the file. It will show up in the second section of Git status. You'll still need to add the change to the staging area (via git add myfile1. js ) and then commit the change.


2 Answers

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.
like image 112
Richard Hansen Avatar answered Sep 21 '22 14:09

Richard Hansen


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.

like image 21
hammar Avatar answered Sep 19 '22 14:09

hammar