Git 未检测到文件且不在 .gitignore 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9707562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git is not detecting a file and is not in .gitignore
提问by jonfer
I have a file called "style.css" and git is not detecting it. It doesn't detect it if I delete it either, but it does detect if I change the name of the file. But I need it with that name. The file is not in the .gitignore file. This is driving me crazy!
我有一个名为“style.css”的文件,而 git 没有检测到它。如果我删除它,它也不会检测到它,但它会检测我是否更改了文件名。但我需要它的名字。该文件不在 .gitignore 文件中。这真让我抓狂!
I would appreciate some help.
我会很感激一些帮助。
回答by kenorb
Use git check-ignore
command to debug your gitignore file (exclude files).
使用git check-ignore
命令来调试你的 gitignore 文件(排除文件)。
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:
或者使用以下命令打印您的.gitignore
in 用户和 repo 文件夹:
cat ~/.gitignore $(git rev-parse --show-toplevel)/.gitignore $(git rev-parse --show-toplevel)/.git/info/exclude
Alternatively use git add -f <path/file>
which allows adding otherwise ignored files.
或者使用git add -f <path/file>
它允许添加否则被忽略的文件。
See: man gitignore
, man git-check-ignore
for more details.
请参阅:man gitignore
,man git-check-ignore
了解更多详情。
回答by Bombe
The file could also be listed in .git/info/exclude
, and there's the option core.excludesfile
to watch, too.
该文件也可以列在 中.git/info/exclude
,并且还可以选择core.excludesfile
观看。
回答by Icestorm0141
Another note, probably a rare case but I had this problem. I moved some files that were already tied to a repo from one directory to another, copy/paste style.
另一个注意事项,可能是一种罕见的情况,但我遇到了这个问题。我将一些已经绑定到存储库的文件从一个目录移动到另一个目录,复制/粘贴样式。
Along with it came the .git folder, which prevented git from detecting the folder.
随之而来的是 .git 文件夹,它阻止了 git 检测文件夹。
So my folder structure was this, with git not detecting Folder 2 even though the repo was set for Original Project 1:
所以我的文件夹结构是这样的,即使 repo 是为原始项目 1 设置的,git 也没有检测到文件夹 2:
--Original Project 1
--.git
--Folder 1
--Folder 2
--.git
--Many other files/folders
Deleting the child .git folder solved my problem.
删除子 .git 文件夹解决了我的问题。
回答by manojlds
Apart from the the gitignore and other places to check for ignore patterns, check if you had run git update-index --assume-unchanged
or git update-index --skip-worktree
. If so, unset them.
除了在 gitignore 和其他地方检查忽略模式之外,检查您是否运行过git update-index --assume-unchanged
或git update-index --skip-worktree
. 如果是这样,请取消设置。
Make sure that there is not some weirdness in the repo or parent of the file under concern whereby it has a .git
of its own.
确保所关注文件的 repo 或父文件中没有任何奇怪之处,因为它有.git
自己的 a。
Try doing a clone of your repo and see if you see the same in the cloned one. If so, try cloning onto a different machine / VM and check. That will give you some idea of what's going wrong where.
尝试克隆你的 repo,看看你是否在克隆的 repo 中看到了相同的内容。如果是这样,请尝试克隆到不同的机器/VM 并检查。这会让你知道哪里出了什么问题。
回答by Lucas
I had the same problem (components/dashboard/js-dev/training/index.js
wasn't being tracked for some reason), so I did the following:
我遇到了同样的问题(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/
Anyways, I found this to be quite weird, so then I took a look at this file, /Users/User/.config/git/ignore
, and this is what it looked like:
无论如何,我发现这很奇怪,所以我看了看这个文件,/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
And it turns out that line 23 is in fact the one between .com.apple.timemachine.donotpresent
and # Directories potentially created on remote AFP share
, in other words, it was a completely empty line!
事实证明,第 23 行实际上是介于.com.apple.timemachine.donotpresent
和之间的那一行# Directories potentially created on remote AFP share
,换句话说,它是一个完全空的行!
I tried removing all the extra newlines so my file looked like this:
我尝试删除所有额外的换行符,因此我的文件如下所示:
# 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
I run git status
, and I notice that it's now picking up components/dashboard/js-dev/training/
. I run git add components/dashboard/js-dev/training/
, and all works fine again.
我跑了git status
,我注意到它现在回升了components/dashboard/js-dev/training/
。我运行git add components/dashboard/js-dev/training/
,一切正常。
Hope this helps someone - this issue got me stuck for an unnecessarily long amount of time.
希望这对某人有所帮助 - 这个问题让我陷入了不必要的长时间。
回答by MzC_
I had a similar issue and solved it.
我有一个类似的问题并解决了它。
I was getting this error message when running the git add
command:
运行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
So I tried to force Git to solve the issue for me by adding a -f
to the git add
command. This would normally force Git to adjust the .gitignore
file and you will then be able to see the required change or problematic setting.
所以我试图通过-f
在git add
命令中添加 a来强制 Git 为我解决这个问题。这通常会强制 Git 调整.gitignore
文件,然后您将能够看到所需的更改或有问题的设置。
In my particular case there seemed to be some weird issue with the newline at the end of the .gitignore
file. Here how Git fixed the problem:
在我的特殊情况下,.gitignore
文件末尾的换行符似乎存在一些奇怪的问题。Git是如何解决这个问题的:
-RemoteSystemsTempFiles
+RemoteSystemsTempFiles
\ No newline at end of file
回答by David Escalona Ozaeta
I also ran into this issue and it seems to be a problem with EGit plugin for Eclipse. Like @user1655478 said in previous comment, selecting the project in the projects view, performing a right click and selecting "Team > Advanced > No assume unchanged" fixed the problem for me.
我也遇到了这个问题,它似乎是 Eclipse 的 EGit 插件的问题。就像@user1655478 在之前的评论中所说的那样,在项目视图中选择项目,执行右键单击并选择“团队 > 高级 > 不假设不变”为我解决了这个问题。
回答by thouliha
Extra note, I ran into this problem and found that changes to files weren't being added to commits. Nothing seemed to work, except Right clicking the project, and doing:
额外注意,我遇到了这个问题,发现对文件的更改没有被添加到提交中。似乎没有任何效果,除了右键单击项目,然后执行以下操作:
Team > Advanced > No assume unchanged
团队 > 高级 > 无假设不变
回答by meth
Another reason to this problem may be the .gitignore_global
file.
In my case, it was automatically produced by Sourcetree
app while i was ignoring file. It was in my user path(/Users/user_name/.gitignore_global
).
此问题的另一个原因可能是.gitignore_global
文件。就我而言,它是Sourcetree
在我忽略文件时由应用程序自动生成的。它在我的用户路径中(/Users/user_name/.gitignore_global
)。
回答by DariusV
In my case I check my .gitignore_global, I found all my swift files ignored, I just removed the line *.swift and git recognized my ones.
在我的情况下,我检查了我的 .gitignore_global,我发现我所有的 swift 文件都被忽略了,我只是删除了 *.swift 行并且 git 识别了我的文件。