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

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

问题描述

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

  * 
!bin / *

然而,这并没有达到预期的效果:我创建了一个新文件在 bin / 中,但是做 git status 仍然显示没有提交(working directory clean )



有任何建议? 这忽略了根文件&然后取消忽略root bin目录:

  / * 
/ * /
! / bin /

通过这种方式,您可以获得所有bin目录,包括子目录及其文件。 p>

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天全站免登陆