为什么 git 不会忽略这些文件? [英] Why are these files not ignored by git?

查看:17
本文介绍了为什么 git 不会忽略这些文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 .gitignore 文件包含以下几行:

 xcuserdata/**/*!xcuserdata/**/xcschemes/*

但是下面的文件还是被跟踪了/MyApp/MyApp.xcodeproj/xcuserdata/colas.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist

为什么会这样?我该如何解决?

PS:如果我有 MyApp.xcodeproj/xcuserdata/colas.xcuserdatad/xcdebugger,这些文件将被忽略.但我不明白为什么它没有这个黑客"就不会忽略它们.

<小时>

编辑 1

与答案之一中所说的相反,模式

 xcuserdata/**/*!xcuserdata/**/xcschemes/*

有效!!!我的意思是,/xcschemes 下的文件被跟踪.

另见帖子 Xcode 项目的 Git 忽略文件,我在那里得到这个 .gitignore 文件.

编辑 2

我的 Git 版本是 1.8.3.4 (Apple Git-47).

编辑 3

当我 git check-ignore 这个文件时,这是我得到的

 致命:不是 git 存储库(或任何父目录):.git

但事实是父目录是一个git目录...

编辑 4

当我 git check-ignore --no-index -- 这个文件时,这就是我得到的

[MT] PluginLoading:需要插件兼容性 UUID 37B30044-3B14-46BA-ABAA-F01000C27B63 用于路径 '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/XcodeSnippetsHelper.xcplugin' 不存在于 DVTPlugInCompatibilityUUID 中2014-02-10 10:03:50.856 xcodebuild[1496:d07] XcodeColors: 加载 (v10.1)2014-02-10 10:03:50.859 xcodebuild[1496:d07] XcodeColors: pluginDidLoad:致命:不是 git 存储库(或任何父目录):.git

编辑 4bis

从根文件夹:

  • 如果我不使用no-index选项,git check-ignore就没有回复.

  • 如果我使用 no-index 选项:我收到错误 error: unknown option 'no-index'...

奇怪;-!

解决方案

首先,你可以做一个 git check-ignore (git 1.8.3.3+) 看看是什么规则忽略了你的文件(假设它不在第一名)

第二,阅读.gitignore 排除文件夹但包括特定子文件夹":<块引用>

如果文件的父目录被排除,则无法重新包含该文件.(*)
(*:除非在 git 2.8+ 中满足某些条件,请参见下文)
出于性能原因,Git 不会列出排除的目录,因此包含文件的任何模式都不起作用,无论它们在哪里定义.

因此无论如何都不会忽略 xcschemes 的文件.
您需要忽略每个父文件夹的父文件夹.
但更好的方法是只忽略文件,然后排除文件夹:

xcuserdata/**!xcuserdata/**/!xcuserdata/**/xcschemes/**

记住:

您需要从 gitignore 规则中排除文件夹,然后才能排除文件.

<小时>

请注意,对于 git 2.9.x/2.10(2016 年中期?),如果排除了该文件的父目录,则可能会重新包含该文件 如果路径中没有通配符> re-include.

Nguyễn Thái Ngọc Duy (pclouds) 正在尝试添加此功能:

然而:

<块引用>

重新包含规则中的目录部分必须是文字(即没有通配符)

所以无论如何这都行不通.

My .gitignore file contains these lines :

 xcuserdata/**/*
 !xcuserdata/**/xcschemes/*

But the following file is still tracked /MyApp/MyApp.xcodeproj/xcuserdata/colas.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist

Why is it so? How can I fix that?

PS: If I had MyApp.xcodeproj/xcuserdata/colas.xcuserdatad/xcdebugger, the files are ignored. But I don't understand why it does not ignore them without this "hack".


EDIT 1

Contrary to what is said in one of the answer, the pattern

 xcuserdata/**/*
 !xcuserdata/**/xcschemes/*

works !!! I mean, the files under /xcschemes are tracked.

See also the post Git ignore file for Xcode projects, where I get this .gitignore file.

EDIT 2

My Git version is 1.8.3.4 (Apple Git-47).

EDIT 3

When I git check-ignore this file, here is what I get

  fatal: Not a git repository (or any of the parent directories): .git

But the fact is that a parent directory is a git directory...

EDIT 4

When I git check-ignore --no-index -- this file, here is what I get

[MT] PluginLoading: Required plug-in compatibility UUID 37B30044-3B14-46BA-ABAA-F01000C27B63 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/XcodeSnippetsHelper.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2014-02-10 10:03:50.856 xcodebuild[1496:d07] XcodeColors: load (v10.1)
2014-02-10 10:03:50.859 xcodebuild[1496:d07] XcodeColors: pluginDidLoad:
fatal: Not a git repository (or any of the parent directories): .git

EDIT 4bis

From the root folder :

  • if I don't use the no-index option, there is no reply to git check-ignore.

  • if I use the no-index option: I get the error error: unknown option 'no-index'...

Strange ;-!

解决方案

First, you can do a git check-ignore (git 1.8.3.3+) to see what rule is ignoring your file (assuming it wasn't in the index in the first place)

Second, read ".gitignore exclude folder but include specific subfolder":

It is not possible to re-include a file if a parent directory of that file is excluded. (*)
(*: unless certain conditions are met in git 2.8+, see below)
Git doesn't list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.

So the file of xcschemes wouldn't be un-ignored anyway.
You needed to ignore parent folder per parent folder.
But a better approach is to ignores files only, and then exclude the folder:

xcuserdata/**
!xcuserdata/**/
!xcuserdata/**/xcschemes/**

Remember:

You need to exclude folders from the gitignore rules before being able to exclude files.


Note that with git 2.9.x/2.10 (mid 2016?), it might be possible to re-include a file if a parent directory of that file is excluded if there is no wildcard in the path re-included.

Nguyễn Thái Ngọc Duy (pclouds) is trying to add this feature:

However:

The directory part in the re-include rules must be literal (i.e. no wildcards)

So that wouldn't have worked here anyway.

这篇关于为什么 git 不会忽略这些文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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