untracked files not shown in git status

偶尔善良 提交于 2019-11-27 02:04:31

问题


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!


回答1:


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.




回答2:


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.




回答3:


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



回答4:


Do you have a .git subdirectory inside your sub_fldr directory? Git may think you're trying to use submodules.




回答5:


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

  1. git ls-files --other --directory --exclude-standard

This will show all untracked files, while obeying the .gitignore file.

  1. 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




回答6:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!