git忽略异常不按需要工作 [英] git ignore exception not working as desired

查看:135
本文介绍了git忽略异常不按需要工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 异常不起作用,因为如果该文件的父目录是不可能重新包含文件排除[来源]。



作为一种丑陋但工作的解决方法,请在文件路径的每个目录级别执行此操作: 目录

  • 重新包含通向您的文件的子目录(或者最终,您的文件)。

    您的条目看起来像这样,每个双行部分为目录层次的一个级别执行这些步骤:

     演示/ ** 
    !演示/路径/

    演示/路径/ **
    !演示/路径/到/

    演示/路径/到/ **
    !演示/路径/到/文件/

    演示/路径/到/文件/ **
    !演示/ path / to / file / file.cpp

    所以,你并不是从排除 Demos / 就像问题作者所做的那样。这是我们文件的父目录,所以你必须在之后重新包含它。相反,首先排除它的内容 Demos / **


    WinXP + mysisGit1.7

    In my .gitignore file, but still can't see Demos/path/to/file/file.cpp being tracked by git.

    I have below entries:

    Demos/
    !Demos/path/to/file/file.cpp
    

    The absolute path is: c:\Project\Demos\path\to\file\file.cpp

    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:

    *.bak
    !tracking.bak
    !/path/to/file/tracking2.bak
    

    It doesn't work ignore folder and exclude some files under that folder. Below won't work:

    /folderUnderRepoRoot/
    !/folderUnderRepoRoot/tracking.cpp
    

    Nor

    anyFolderNamedLikeThis/
    !anyFolderNamedLikeThis/tracking.cpp
    !/anyFolderNamedLikeThis/tracking.cpp
    

    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.

    /folderUnderRepoRoot/*
    /folderUnderRepoRoot/tracking.cpp
    

    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 .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].

    As an ugly-but-working workaround, do this on every directory level on the path to your file:

    1. exclude all content of the directory
    2. re-include the sub-directory leading to your file (or finally, your file).

    Your entries would look like this, with each two-line section executing these steps for one level of the directory hierarchy:

    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
    

    So, you don't start by excluding 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/**.

    这篇关于git忽略异常不按需要工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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