Git没有检测到文件,不在.gitignore中

我有一个名为“style.css”的文件,git没有检测到它。 如果我删除它,它不检测它,但它确实检测我是否更改文件的名称。 但是我需要这个名字。 该文件不在.gitignore文件中。 这真让我抓狂!

我将不胜感激一些帮助。

该文件也可以在.git/info/exclude列出,还有core.excludesfile选项core.excludesfile观看。

使用git check-ignore命令来debugging你的gitignore文件(排除文件)。

例如:

 $ git check-ignore -v config.php .gitignore:2:src config.php 

上面的输出详细介绍了每个给定path名(包括行)的匹配模式(如果有的话)。

所以也许你的文件扩展名不会被忽略,而是整个目录。

返回的格式是:

 <source> <COLON> <linenum> <COLON> <pattern> <HT> <pathname> 

或者使用以下命令在用户和repo文件夹中打印.gitignore

 cat ~/.gitignore $(git rev-parse --show-toplevel)/.gitignore $(git rev-parse --show-toplevel)/.git/info/exclude 

或者使用git add -f ,它允许添加被忽略的文件。

请参阅: man gitignoreman git-check-ignore了解更多详情。

除了gitignore和其他地方检查忽略模式,检查你是否运行git update-index --assume-unchanged或者git update-index --skip-worktree 。 如果是这样,请取消它们。

确保所关注的文件的回购或父项中没有一些古怪的东西,因为它有自己的.git

尝试做一个你的回购克隆,看看你是否看到在克隆相同。 如果是这样,请尝试克隆到不同的机器/ VM并检查。 这会给你一些什么地方出错的想法。

我有一个类似的问题,解决了它。

运行git add命令时遇到了这个错误消息:

 The following paths are ignored by one of your .gitignore files: <file> Use -f if you really want to add them. fatal: no files added 

所以我试着强制Git通过在git add命令中添加-f来解决这个问题。 这通常会强制Git调整.gitignore文件,然后您将能够看到所需的更改或有问题的设置。

在我的特殊情况下,在.gitignore文件结尾的换行符似乎有一些奇怪的问题。 这里Git如何解决这个问题:

 -RemoteSystemsTempFiles +RemoteSystemsTempFiles \ No newline at end of file 

我有同样的问题( components/dashboard/js-dev/training/index.js由于某种原因未被跟踪),所以我做了以下操作:

 $ git check-ignore -v components/dashboard/js-dev/training/index.js $ (gave me nothing) $ git check-ignore -v components/dashboard/js-dev/training/ $ /Users/User/.config/git/ignore:23: components/dashboard/js-dev/training/ 

无论如何,我发现这很奇怪,于是我看了一下这个文件/Users/User/.config/git/ignore ,这就是它的样子:

 (this is line 1) # Automatically created by GitHub for Mac # To make edits, delete these initial comments, or else your changes may be lost! *.DS_Store .AppleDouble .LSOverride # Icon must end with two \r Icon # Thumbnails ._* # Files that might appear in the root of a volume .DocumentRevisions-V100 .fseventsd .Spotlight-V100 .TemporaryItems .Trashes .VolumeIcon.icns .com.apple.timemachine.donotpresent # Directories potentially created on remote AFP share .AppleDB .AppleDesktop Network Trash Folder Temporary Items .apdisk 

事实certificate,第23行实际上是.com.apple.timemachine.donotpresent# Directories potentially created on remote AFP share之间的一个,换句话说,它是一个完全空的行!

我试图删除所有额外的换行符,所以我的文件看起来像这样:

 # Automatically created by GitHub for Mac # To make edits, delete these initial comments, or else your changes may be lost! *.DS_Store .AppleDouble .LSOverride # Icon must end with two \r Icon # Thumbnails ._* # Files that might appear in the root of a volume .DocumentRevisions-V100 .fseventsd .Spotlight-V100 .TemporaryItems .Trashes .VolumeIcon.icns .com.apple.timemachine.donotpresent # Directories potentially created on remote AFP share .AppleDB .AppleDesktop Network Trash Folder Temporary Items .apdisk 

我运行git status ,我注意到它现在正在拾取components/dashboard/js-dev/training/ 。 我运行git add components/dashboard/js-dev/training/ ,并且一切正常。

希望这可以帮助别人 – 这个问题让我陷入了不必要的长时间。

另一个说明,可能是一个罕见的情况,但我有这个问题。 我将一些已经绑定到一个目录的文件复制/粘贴到另一个目录。

随之而来的是.git文件夹,它阻止了git检测文件夹。

所以我的文件夹结构是这样的,即使回购被设置为原始项目1,git没有检测到文件夹2:

 --Original Project 1 --.git --Folder 1 --Folder 2 --.git --Many other files/folders 

删除孩子.git文件夹解决了我的问题。

额外的注意,我遇到了这个问题,发现文件的变化没有被添加到提交。 似乎没有什么工作,除了右键单击该项目,并执行:

团队>高级>没有任何变化

我也遇到了这个问题,它似乎是与Eclipse的EGit插件的问题。 像@ user1655478在之前的评论中所说的,在项目视图中select项目,右键单击并select“团队>高级>不承担”,为我解决了这个问题。

如果你的项目是maven项目,请检查你是否更改了src文件或目标文件。 这就是我最近做的。 由于文件path引用太长,我没有注意到path中的“目标”。 痛苦1小时后,所有的好。

我遇到了另一个原因。 可能非常罕见的情况。

我复制我的整个存储库到另一个文件夹来处理它。 我对一个子模块所做的更改没有被git检测到。 原来,submodule文件夹中的.git文件包含对原始文件的绝对文件引用。 只要我更正文件参考指向我的工作副本一切都很好。