使 .gitignore 忽略除少数文件之外的所有内容 [英] Make .gitignore ignore everything except a few files

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

问题描述

我知道 .gitignore 文件掩盖了 Git 版本中的指定文件控制.我有一个项目 (LaTeX) 会生成很多额外的文件 (.auth,.dvi、.pdf、日志等),但我不希望跟踪它们.

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.

但是,是否有任何可行的方法可以将输出文件保存在根目录中?项目树并使用 .gitignore 忽略除我所在的文件之外的所有内容用 Git 跟踪?类似的东西

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