我如何告诉 Git 忽略除子目录之外的所有内容? [英] How do I tell Git to ignore everything except a subdirectory?

查看:24
本文介绍了我如何告诉 Git 忽略除子目录之外的所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想忽略存储库中的所有文件,除了出现在 bin 子目录中的文件.我尝试将以下内容添加到我的 .gitignore:

<预><代码>*!bin/*

然而,这并没有达到预期的效果:我在 bin/ 中创建了一个新文件,但是执行 git status 仍然显示 没有提交(工作目录干净).

有什么建议吗?

解决方案

这会忽略根文件 &根目录,然后取消忽略根 bin 目录:

/*/*/!/斌/

这样你就可以得到所有的 bin 目录,包括子目录和它们的文件.

I want to ignore all files in my repository except those that occur in the bin subdirectory. I tried adding the following to my .gitignore:

*
!bin/*

This does not have the desired effect, however: I created a new file inside of bin/, but doing git status still shows nothing to commit (working directory clean).

Any suggestions?

解决方案

This ignores root files & root directories, then un-ignores the root bin directory:

/*
/*/
!/bin/

This way you get all of the bin directory, including subdirectories and their files.

这篇关于我如何告诉 Git 忽略除子目录之外的所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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