让.gitignore忽略除几个文件以外的所有内容 [英] Make .gitignore ignore everything except a few files

查看:1209
本文介绍了让.gitignore忽略除几个文件以外的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道一个.gitignore文件隐藏了Git版本
控件中的指定文件。我有一个项目(LaTeX)在运行时会生成大量额外的文件(.auth,
.dvi,.pdf,日志等),但我不希望跟踪这些文件。



我知道我可以(也许应该)制作它,这样所有这些文件都放在项目中的
单独的子文件夹中,因为我可以忽略该文件夹。

然而,是否有任何可行的方法将输出文件保存在
项目树的根目录中,并使用.gitignore忽略除文件I之外的所有内容'm
用Git跟踪?就像

 #忽略所有内容
*

#但不是这些文件...
script.pl
template.latex
#etc ...


解决方案


一个可选的前缀
之前排列的任何匹配文件将再次包含在内。如果一个否定模式匹配,
将覆盖较低的优先模式源。




 #忽略所有内容
*

#但不是这些文件...
!.gitignore
!script.pl
!template.latex
#etc ...

#...即使它们在子目录中
!* /

#如果文件被跟踪的是子目录
!* / a / b / file1.txt
!* / a / b / c / *


I understand that a .gitignore file cloaks specified files from Git's version control. I have a project (LaTeX) that generates lots of extra files (.auth, .dvi, .pdf, logs, etc) as it runs, but I don't want those to be tracked.

I'm aware that I could (maybe should) make it so all those files are put in an separate subfolder in the project, since I could then just ignore the folder.

However, is there any feasible way to keep the output files in the root of the project tree and use .gitignore to ignore everything except the files I'm tracking with Git? Something like

# Ignore everything
*

# But not these files...
script.pl
template.latex
# etc...

解决方案

An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources.

# Ignore everything
*

# But not these files...
!.gitignore
!script.pl
!template.latex
# etc...

# ...even if they are in subdirectories
!*/

# if the files to be tracked are in subdirectories
!*/a/b/file1.txt
!*/a/b/c/*

这篇关于让.gitignore忽略除几个文件以外的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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