Git忽略,除了特定的子目录 [英] Git ignore except specific subdirectories

查看:68
本文介绍了Git忽略,除了特定的子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过一些示例,该示例说明了如何忽略除某些子目录之外的所有内容.

I've looked at some examples on how to ignore everything except certain sub directories like so.

# Ignore Everything
foo/*
# Include sub directory
!foo/ccc/*

我也尝试过:

# Ignore Everything
foo/*
# Include sub directory
!foo/ccc/

更新

因此,上面的代码有效,但是尝试排除另一个目录中另一个目录中的目录不起作用.它仅适用于父目录和子目录.

So the code above works, however trying to exclude a directory within another directory within another does not work. It only works on the parent directory and sub directory.

# Ignore Everything
foo/*
# Include sub directory
!foo/ccc/aaa/ddd/ 

将其包含在gitingore中之后,我运行了git add --all,但没有在git status中看到任何文件.

After I include this in my gitingore, I run a git add --all and I dont see any the files in git status.

所有帮助将不胜感激.

推荐答案

您必须取消忽略要取消忽略的路径中的每个目录.像下面这样的情况应该适用于您的情况:

You have to unignore every directory in the path that you wish to unignore. Something like the following should work in your case:

# Ignore everything in foo
foo/*
# Except the ccc subdir
!foo/ccc

# Ignore everything in ccc subdir
foo/ccc/*
# Except the aaa subsubdir
!foo/ccc/aaa

# Ignore everything in aaa subsubdir
foo/ccc/aaa/*
# Except the ddd subsubsubdir
!foo/ccc/aaa/ddd

忽略规则以/*结尾很重要,因为它告诉git忽略文件夹中的所有内容,而不是文件夹本身,这使我们可以为特定子目录的忽略规则添加例外.

It's important that the ignore rules end in /*, as that tells git to ignore everything in the folder, but not the folder itself, permitting us to add exceptions to the ignore rules for specific subdirectories.

这篇关于Git忽略,除了特定的子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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