未跟踪的文件未在git状态中显示 [英] untracked files not shown in git status

查看:485
本文介绍了未跟踪的文件未在git状态中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下文件夹结构的项目:



所有项目文件位于base_fldr文件夹中。另外我有一些名为sub_fldr1和sub_fldr2的base_fldr文件夹。这些子文件夹还包含一些文件。



如果我修改了base_fldr或base_fldr \sub_fldr\中的任何文件,那么git状态会将它们显示为已修改。此外,如果我添加一个新的文件base_fldr,git状态将显示为未跟踪的文件。



我的问题是,如果我添加一个新的文件base_fldr\sub_fldr\那么git状态不会将文件显示为未跟踪。它甚至不会提供有关该文件的任何信息。



该文件或其扩展名不在我的.gitignore列表中。我也尝试了git add sub_fldr \ file_name,但它既没有给出错误,也没有将该文件添加到索引中。



有什么想法发生了什么?谢谢!

解决方案

我想清楚发生了什么问题。基本上我的.gitignore文件的第一行是* /。这会导致添加到子目录的任何文件被git status命令忽略。但有趣的是,如果我修改子文件夹中的任何文件,git状态正确显示它们已修改,因为该文件已存在于git存储库中,但忽略了子文件夹中的新文件。



我通过删除.gitignore文件中的行来解决问题,以避免忽略子文件夹中的更改,然后将新文件添加到索引,然后再次将该行添加回.gitignore中,以便它将忽略任何生成的文件子文件夹。



感谢所有回复。

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.

这篇关于未跟踪的文件未在git状态中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆