Git忽略a子目录下所有txt文件的问题排查及解决
Ignoring All TXT Files in Subdirectories of
a/ If your directory structure looks like this:
a |-- b | |-- qfq.txt | |-- ewfw.txt | | ... |-- c | |-- wgfw.txt | |-- wjkh.txt | | ... ...
And you’re aiming to ignore every .txt file under all subdirectories of a/, here’s the breakdown of what works and why the initial confusion happened:
- The rule
/a/**/*.txtis actually valid and effective for your use case. - The reason you might have thought it wasn’t working is because Git doesn’t track or commit empty directories. Once all
.txtfiles in subdirectories likeb/orc/are ignored, those directories disappear from Git’s tracked files list—making it seem like the ignore rule failed, but it’s actually doing exactly what you want. Any new.txtfiles added to these subdirectories will be automatically ignored, and existing ones won’t show up in future commits.
Huge thanks to @JonathonReinhar, @phd, and pankaj for their quick and helpful responses that cleared up this confusion!
内容的提问来源于stack exchange,提问作者Somesh Jaiswal
相关产品推荐
相关产品推荐

