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 f开发者_开发技巧rom 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,
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 ingit status
. You can turn off the 'assume unchanged' bit by runninggit 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
iss
orS
then the 'skip-worktree' bit is set. You can turn off the 'skip-worktree' bit by runninggit 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 runninggit update-index --really-refresh
. If your working directory is on a network drive (NFS, sshfs, etc.) try moving your repository to a local drive.
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.
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
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
It is most likely ignored by your .gitignore
file.
Call git status --ignored
and see if your file appears.
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
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.
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.
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.
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.
精彩评论