忽略.gitignore中的所有内容并添加子文件夹不起作用 [英] Ignoring everything in .gitignore and adding subfolder does not work

查看:133
本文介绍了忽略.gitignore中的所有内容并添加子文件夹不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下.gitignore:

I have the following .gitignore:

# Ignore everything
/*
!/.gitignore

# Readd folders:
#!/mainfolder/ # this works!
!/mainfolder/subfolder/
!/mainfolder/subfolder/*

我想忽略所有内容,但subfolder/.添加行!/mainfolder/可以,因此/mainfolder不再被忽略.但是我只想添加subfolder/下面的内容,而subfolder/的第二行和第三行不起作用.

I want to ignore everything, but subfolder/. Adding the line !/mainfolder/ works, so that /mainfolder is not ignored anymore. But I want to add only the things below subfolder/ and the second and third lines for subfolder/ do not work.

我在网上发现了一些链接,提示这是正确的方法(例如

I have found several links online suggesting this is the correct way (e.g. this one). So what am I doing wrong?!

我正在Windows 10上使用SourceTree的Git 2.17.1.我已经从集成的MINGW64 bash测试了这些结果.

I am using Git 2.17.1 from SourceTree on Windows 10. I have tested these results from the integrated MINGW64 bash.

推荐答案

您需要先将文件夹白名单,然后将文件白名单:

You need to whitelist folders first, then files:

*
!.gitignore
!/mainfolder/
/mainfolder/*
!/mainfolder/subfolder/
!/mainfolder/subfolder/**

对于仍被忽略的任何文件,请使用以下命令检查原因:

For any file still ignored, check why with:

git check-ignore -v -- path/to/ignored/file


是否有可能将答案扩展到更深的子文件夹?例如.除了"deepsubfolder"(?)外,我将如何忽略一切:!/mainfolder/subfolder/deepsubfolde

would it be possible to extend the answer on how you would do this for a deeper subfolder? E.g. how would I ignore everything except ´deepsubfolder´(?): !/mainfolder/subfolder/deepsubfolde

类似于" Git-忽略存储库中位于任何位置的文件夹,该文件夹可递归地允许所有操作":

*
!.gitignore
!*/
!**/deepsubfolder/**

这篇关于忽略.gitignore中的所有内容并添加子文件夹不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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