git ignore exception not working multiple subdirectories below ignored directory

我的梦境 提交于 2019-12-08 04:24:20

问题


I am having an issue where the exception syntax for gitignore (!fileName.txt) is not working when the file is multiple subdirectories below the ignored directory.

For instance:

web/[Ee]xample.[Ww]eb/[Ss]itecore/*
!web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/[Ss]tandard/[Cc]ustom/32x32*

does not include the files in the folder 32x32.
I have to manually add them via command line like so:

git add -f -r web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/[Ss]tandard/[Cc]ustom/32x32

Is there a way to use the exception operator in a situation like this?


回答1:


Re-including a file that "is multiple subdirectories below the ignored directory" (as you try), 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, re-include all parent directories along the path before re-including your desired file, while keeping the files in these parent directories out by re-excluding them.

For your example it would like as follows:

web/[Ee]xample.[Ww]eb/[Ss]itecore/*

!web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/
web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/**
!web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/
web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/**
!web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/[Ss]tandard/
web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/[Ss]tandard/**
!web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/[Ss]tandard/[Cc]ustom/
web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/[Ss]tandard/[Cc]ustom/**
!web/[Ee]xample.[Ww]eb/[Ss]itecore/[Ss]hell/[Tt]hemes/[Ss]tandard/[Cc]ustom/32x32*

Source: my related answer here.

Alternatively, you could instead use .gitignore files that are placed in the directory of files to re-include [more here]. Depending on taste, this could be the prettier solution.



来源:https://stackoverflow.com/questions/19100058/git-ignore-exception-not-working-multiple-subdirectories-below-ignored-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!