git忽略异常不按需要工作 [英] git ignore exception not working as desired
问题描述
WinXP + mysisGit1.7
在我的.gitignore文件中,仍然看不到 Demos / path / to / file / file .cpp
被git跟踪。
我有以下资料:
演示/
!Demos / path / to / file / file.cpp
绝对路径为: c:\Project\Demos\path\to\file\file.cpp
什么可能是错误的?请帮助,谢谢。
编辑:
我发现mysisGit .gitignore在WindowsXP上的工作方式只能忽略某些类型的文件,然后排除一些具有相同类型的文件。例如:
*。bak
!tracking.bak
!/ path / to / file / tracking2.bak
它不起作用忽略文件夹并排除该文件夹下的某些文件。下面是不行的:
/ folderUnderRepoRoot /
!/folderUnderRepoRoot/tracking.cpp
code>
也不是
anyFolderNamedLikeThis /
!anyFolderNamedLikeThis / tracking.cpp
!/anyFolderNamedLikeThis/tracking.cpp
但是,我发现有一个例外。有一种解决方法可以在被忽略的文件夹下(而不是其子文件夹)排除文件。 This works。
/ folderUnderRepoRoot / *
/folderUnderRepoRoot/tracking.cpp
但是这种方式仅限于文件不在任何子文件夹中,所以它不是很有用。
因此,我最终还是提交了大部分源文件,即使我只在跟踪其他大项目时感兴趣一些文件。这意味着有一堆我不会碰到但仍然需要提交的文件。
这里是另一个线程,它有类似的问题。
.gitignore
异常不起作用,因为如果该文件的父目录是不可能重新包含文件排除[来源]。 作为一种丑陋但工作的解决方法,请在文件路径的每个目录级别执行此操作: 目录 您的条目看起来像这样,每个双行部分为目录层次的一个级别执行这些步骤: 所以,你并不是从排除 WinXP + mysisGit1.7 In my .gitignore file, but still can't see I have below entries: The absolute path is: What could be wrong? Please help, thanks. EDIT: I found the way how mysisGit .gitignore work on WindowsXP can only ignore certain type of file, then exclude some files with same type. For example: It doesn't work ignore folder and exclude some files under that folder. Below won't work: Nor However, I do find that there's an exception. There's a work-around way to exclude files just right under the ignored folder (not to its subfolder). This works. But this way is only limited when the file is not in any subfolder, so it's not so useful. So I end up still commit most of source files, even I was only interested in a few files while tracking some others big project. Which means there're a bunch of files I won't touch but still need to commit them. Here is another thread that had similar problem. Your As an ugly-but-working workaround, do this on every directory level on the path to your file: Your entries would look like this, with each two-line section executing these steps for one level of the directory hierarchy: So, you don't start by excluding 这篇关于git忽略异常不按需要工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
演示/ **
!演示/路径/
演示/路径/ **
!演示/路径/到/
演示/路径/到/ **
!演示/路径/到/文件/
演示/路径/到/文件/ **
!演示/ path / to / file / file.cpp
Demos /
就像问题作者所做的那样。这是我们文件的父目录,所以你必须在之后重新包含它。相反,首先排除它的内容: Demos / **
。Demos/path/to/file/file.cpp
being tracked by git. Demos/
!Demos/path/to/file/file.cpp
c:\Project\Demos\path\to\file\file.cpp
*.bak
!tracking.bak
!/path/to/file/tracking2.bak
/folderUnderRepoRoot/
!/folderUnderRepoRoot/tracking.cpp
anyFolderNamedLikeThis/
!anyFolderNamedLikeThis/tracking.cpp
!/anyFolderNamedLikeThis/tracking.cpp
/folderUnderRepoRoot/*
/folderUnderRepoRoot/tracking.cpp
.gitignore
exception does not work because "It is not possible to re-include a file if a parent directory of that file is excluded" [source].
Demos/**
!Demos/path/
Demos/path/**
!Demos/path/to/
Demos/path/to/**
!Demos/path/to/file/
Demos/path/to/file/**
!Demos/path/to/file/file.cpp
Demos/
like the question author did. It's a parent directory of our file, so you would have to re-include it right afterwards. Instead, start by excluding its contents: Demos/**
.