Git 忽略不在 gitignore 中的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9436405/
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 ignoring files that aren't in gitignore
提问by Ian Hunter
I have a git repository that is ignoring image files as well as a few other files, but my .gitignore
file only has it ignoring a config.php
file. Is there some global ignore file somewhere that I can't seem to find? I have to specify files to add them now, and it's giving me this warning:
我有一个忽略图像文件和其他一些文件的 git 存储库,但我的.gitignore
文件只忽略了一个config.php
文件。是否有一些我似乎找不到的全局忽略文件?我现在必须指定文件来添加它们,它给了我这个警告:
The following paths are ignored by one of your .gitignore files.
您的 .gitignore 文件之一将忽略以下路径。
The contents of my ~/.gitconfig
file are only my e-mail address.
我的~/.gitconfig
文件的内容只是我的电子邮件地址。
回答by kenorb
git check-ignore
git check-ignore
Use git check-ignore
commandto debug your gitignore file (exclude files).
使用git check-ignore
命令来调试你的 gitignore 文件(排除文件)。
For 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 HOME and repository folder:
或者使用以下命令打印您.gitignore
在用户 HOME 和存储库文件夹中:
cat ~/.gitignore "$(git rev-parse --show-toplevel)"/.gitignore "$(git rev-parse --show-toplevel)"/.git/info/exclude
cat ~/.gitignore "$(git rev-parse --show-toplevel)"/.gitignore "$(git rev-parse --show-toplevel)"/.git/info/exclude
Alternatively use git add -f
which allows adding otherwise ignored files.
或者使用git add -f
它允许添加否则被忽略的文件。
See: man gitignore
, man git-check-ignore
for more details.
请参阅:man gitignore
,man git-check-ignore
了解更多详情。
Syntax
句法
git check-ignore [options] pathname…?
git check-ignore [options] --stdin
git check-ignore [options] 路径名...?
git check-ignore [选项] --stdin
回答by gabrielf
It might be good to know that your git configuration can contain a core.excludesfile which is a path to a file with additional patterns that are ignored. You can find out if you have such a configuration by running (in the problematic git repo):
知道您的 git 配置可以包含一个 core.excludesfile 可能是件好事,它是一个文件的路径,其中包含被忽略的其他模式。您可以通过运行(在有问题的 git repo 中)来确定您是否有这样的配置:
git config core.excludesfile
If it prints a file path, look at the contents of that file for further information.
如果它打印文件路径,请查看该文件的内容以获取更多信息。
In my case I installed git via an old version of boxenwhich ignored the pattern 'Icon?' that in my case gave me the warning, mentioned in this question, for a folder icons (I'm on a case insensitive filesystem that's why Icon? matches icons).
在我的情况下,我通过旧版本的boxen安装了 git,它忽略了模式“图标?” 在我的情况下,这给了我警告,在这个问题中提到,对于文件夹图标(我在一个不区分大小写的文件系统上,这就是为什么 Icon?匹配图标)。
回答by gahooa
Check these out:
检查这些:
Have you looked for other .gitignore files, as there can be many of them.
Also, look at REPO/.git/config to see if there is anything there.
Repo exclude Local per-repo rules can be added to the .git/info/exclude file in your repo. These rules are not committed with the repo so they are not shared with others. This method can be used for locally-generated files that you don't expect other users to generate, like files created by your editor.
您是否查找过其他 .gitignore 文件,因为其中可能有很多。
另外,查看 REPO/.git/config 以查看是否有任何内容。
Repo exclude 本地 per-repo 规则可以添加到 repo 中的 .git/info/exclude 文件中。这些规则不与 repo 一起提交,因此不会与其他人共享。此方法可用于您不希望其他用户生成的本地生成文件,例如由您的编辑器创建的文件。
回答by Shevaun
I had the same problem - a directory was being ignored by git with this error:
我遇到了同样的问题 - git 忽略了一个目录并出现此错误:
? git add app/views/admin/tags/
The following paths are ignored by one of your .gitignore files:
app/views/admin/tags
Use -f if you really want to add them.
fatal: no files added
I finally figured out my problem was a line in my ~/.gitignore_global
:
我终于发现我的问题是我的~/.gitignore_global
:
TAGS
which was matching the path app/views/admin/tags
. I fixed it by adding a leading slash to the global gitignore file
这是匹配的路径app/views/admin/tags
。我通过在全局 gitignore 文件中添加前导斜杠来修复它
/TAGS
and git started tracking my directory again.
然后 git 再次开始跟踪我的目录。
回答by Brian
For me I accidentally had a wildcard in my ~/.gitignore_global file. Maybe check there?
对我来说,我不小心在 ~/.gitignore_global 文件中有一个通配符。也许检查那里?
回答by Matt Montag
Another thing to try: I had a directory B with its own .git
repository nested under my project directory A (but not as a submodule). I made some changes to B, and wanted to make it into a bonafide submodule. I believe git A was automatically ignoring B because it contained its own repository (see Nested git repositories without submodules?). I renamed the B folder, and tried to clone it again as a submodule, and that was bringing me the misleading "ignored by .gitignore" error message. The solution was to delete .git
out of B.
另一件事要尝试:我有一个目录 B,它有自己的.git
存储库嵌套在我的项目目录 A 下(但不是作为子模块)。我对 B 进行了一些更改,并希望将其变成一个真正的子模块。我相信 git A 会自动忽略 B,因为它包含自己的存储库(请参阅没有子模块的嵌套 git 存储库?)。我重命名了 B 文件夹,并尝试将其作为子模块再次克隆,这给我带来了误导性的“被 .gitignore 忽略”错误消息。解决办法是删除 .git
B。
回答by Bukov
I was having the exact same problem as you. The only reply you got listed a few places to check, but none of them solved the problem for me, and from your comment I don't think for you either. I had no OTHER .gitignore files hiding lower in the directory tree; nothing in .git/config; nothing in .git/ingore/exclude
我遇到了和你完全一样的问题。你得到的唯一答复列出了几个要检查的地方,但没有一个为我解决了问题,从你的评论中我也不认为你。我没有隐藏在目录树中的其他 .gitignore 文件;.git/config 中没有任何内容;.git/ingore/exclude 中没有任何内容
If you still have the problem, check this answer. It solved the issue for me
如果您仍然有问题,请查看此答案。它为我解决了这个问题
Basically, check for a ~/.gitignore file. Mine was called ~/.gitignore_global. I don't know when it was created (Icertainly didn't make it), but I tried a ton of different git setup's when I first installed, so one of them must have put it there.
基本上,检查 ~/.gitignore 文件。我的被称为 ~/.gitignore_global。我不知道它是什么时候创建的(我当然没有成功),但是当我第一次安装时,我尝试了大量不同的 git 设置,所以其中一个肯定已经把它放在那里了。
Hope his answer helps you as well!
希望他的回答也能帮到你!
回答by Conrad Jones
Check you have permission to the folder. I have just run into this and it was because the folder was owned by the www-data user not the user I was logged in to the terminal as.
检查您是否有权访问该文件夹。我刚刚遇到了这个问题,这是因为该文件夹归 www-data 用户所有,而不是我登录到终端的用户。
回答by Ger Hobbelt
Another reason for receiving this error message from git is when executing the git submodule add
command while a previous git command has crashed and left the lock file (this can happen, for instance, when you use custom scripts which include git commands and you haven't noted the crash).
从 git 收到此错误消息的另一个原因是git submodule add
在前一个 git 命令崩溃并离开锁定文件时执行该命令(例如,当您使用包含 git 命令的自定义脚本并且您没有注意到碰撞)。
If you execute the command git commit
instead, while none of the conditions have changed (git submodule add
will keep yelling that your .gitignore
files are to blame), you'll see anothererror report instead:
如果您git commit
改为执行该命令,而条件没有改变(git submodule add
将继续大喊您的.gitignore
文件是罪魁祸首),您将看到另一个错误报告:
$ git commit -a
fatal: Unable to create '..../.git/index.lock': File exists.
If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
and indeed deleting the lockfile:
并确实删除了锁定文件:
rm .git/index.lock
resolves the issue. (This happens to git version 2.1.0.9736. It may be fixed in future git releases.)
解决了这个问题。(这发生在 git 版本 2.1.0.9736。它可能会在未来的 git 版本中修复。)
回答by Maharlikans
One more thing: if the directory you're in requires root access for writing or executing, make sure you're on the root user. I actually got a weird error where I was trying to add a submodule and git kept complaining that the path I was cloning into was being ignored by a git ignore file. Then I changed to root user, ran the submodule add again, and there was no problem.
还有一件事:如果您所在的目录需要 root 访问权限才能写入或执行,请确保您使用的是 root 用户。我实际上在尝试添加子模块时遇到了一个奇怪的错误,而 git 一直抱怨我克隆到的路径被 git ignore 文件忽略了。然后我改成root用户,再次运行submodule add,就没有问题了。