I have a project with the following folder structure:
All the project files are in base_fldr folder. Also I have a few folders inside base_fldr called sub_fldr1 and sub_fldr2. These sub folders also contain some files.
If I modify any of the files inside my base_fldr or base_fldr\sub_fldr\ then git status shows them as modified. Also if I add a new file to base_fldr, git status will show it as untracked file.
My problem is if I add a new file inside base_fldr\sub_fldr\ then the git status doesn't show the file as untracked. It won't even give any info about the file.
The file or its extension is NOT in my .gitignore list. Also I did try git add sub_fldr\file_name but neither it gave an error nor it add the file to index.
Any idea what's happening here? Thanks!
I figured out what was going wrong. Basically the first line in my .gitignore file is "*/". This causes any file added to sub directory being ignored by git status command. But the funny thing was if I modify any files in sub folder, git status correctly shows them as modified as the file is already in git repository, but was ignoring new files in sub folder.
I fixed my issue by removing the line in .gitignore file to not ignore changes in sub folders, then added the new files to index and then again added back the line in .gitignore so that it will ignore any generated files in subfolders.
Thanks all for the responses.
This is likely because your base_fldr\sub_fldr\ directory is untracked, if you run:
git add base_fldr\sub_fldr\
From within your working copy root, it will automatically add the directory and other files and directories within that directory as well.
By default, git will not show files within directories that are untracked.
I ran into a similar issue with missing tracked files. While experimenting with ways to manage locally modified versions of tracked files without having to constantly avoid accidental commits, I ran the following:
git update-index --assume-unchanged my-tracked-file-that-is-awol
I ended up scrapping this idea, but forgot to undo the command, so subsequent changes to this and other --assume-unchanged files were completely missing from:
git status -u --ignored
It took me a while to figure out what was going on, but I simply had to reverse the command with:
git update-index --no-assume-unchanged my-tracked-file-that-is-awol
Do you have a .git subdirectory inside your sub_fldr directory? Git may think you're trying to use submodules.
In order to debug an issue like this, see if your .gitignore file is the culprit by observing the following two outputs
See https://git-scm.com/docs/git-ls-files
git ls-files --other --directory --exclude-standard
This will show all untracked files, while obeying the .gitignore file.
git ls-files --other --directory
This will show all untracked files, without obeying the .gitignore file.
Whichever files are present in output of 2, but are not present in output of 1, are not shown in untracked because of some flag in your .gitignore file
Here is another cause of the behavior described in this question (git status untracked files list doesn't include an untracked file in a sub-folder). If the file is untracked because of a .gitignore file in the sub-folder then the file won't be included in the git status untracked files list.
来源:https://stackoverflow.com/questions/4610561/untracked-files-not-shown-in-git-status