.gitignore java web_使.gitignore忽略除少数文件以外的所有内容

我知道.gitignore文件会掩盖Git版本控制中的指定文件。 我有一个项目(LaTeX),它在运行时会生成许多其他文件(.auth,.dvi,.pdf,日志等),但我不希望这些文件被跟踪。

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

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

# Ignore everything

*

# But not these files...

script.pl

template.latex

# etc...

#1楼

要忽略目录中的某些文件,必须以正确的顺序执行此操作:

例如,忽略文件夹“ application”中的所有内容,但index.php和文件夹“ config”中要注意该顺序 。

您必须否定要先想要的东西。

失败

application/*

!application/config/*

!application/index.php

作品

!application/config/*

!application/index.php

application/*

#2楼

如果要忽略目录中除其中一个文件之外的全部内容,可以为文件路径中的每个目录编写一对规则。 例如.gitignore忽略pippo文件夹,除了pippo / pluto / paperino.xml

.gitignore

pippo/*

!pippo/pluto

pippo/pluto/*

!pippo/pluto/paperino.xml

#3楼

更具体一点:

示例:忽略webroot/cache所有内容-但保留webroot/cache/.htaccess 。

请注意cache文件夹后的斜杠(/):

失败

webroot/cache*

!webroot/cache/.htaccess

作品

webroot/cache/*

!webroot/cache/.htaccess

#4楼

我有来自凉亭的Jquery和Angular。 Bower将它们安装在

/public_html/bower_components/jquery/dist/bunch-of-jquery-files

/public_html/bower_components/jquery/src/bunch-of-jquery-source-files

/public_html/bower_components/angular/angular-files

最小化的jquery在dist目录中,angular在angular目录中。 我只需要将最小化的文件提交到github。 一些篡改.gitignore,这是我设法想到的...

/public_html/bower_components/jquery/*

!public_html/bower_components/jquery/dist

/public_html/bower_components/jquery/dist/*

!public_html/bower_components/jquery/dist/jquery.min.js

/public_html/bower_components/angular/*

!public_html/bower_components/angular/angular.min.js

希望有人能发现这个有用。

#5楼

在大多数情况下,您想使用/*代替*或*/

使用*是有效的,但是它可以递归工作。 从此以后,它就不再查找目录。 人们建议再次使用!*/将目录列入白名单,但最好使用/*将最高级别的文件夹列入黑名单

# Blacklist files/folders in same directory as the .gitignore file

/*

# Whitelist some files

!.gitignore

!README.md

# Ignore all files named .DS_Store or ending with .log

**/.DS_Store

**.log

# Whitelist folder/a/b1/ and folder/a/b2/

# trailing "/" is optional for folders, may match file though.

# "/" is NOT optional when followed by a *

!folder/

folder/*

!folder/a/

folder/a/*

!folder/a/b1/

!folder/a/b2/

!folder/a/file.txt

# Adding to the above, this also works...

!/folder/a/deeply

/folder/a/deeply/*

!/folder/a/deeply/nested

/folder/a/deeply/nested/*

!/folder/a/deeply/nested/subfolder

上面的代码将忽略.gitignore , README.md , folder/a/file.txt , folder/a/b1/和folder/a/b2/所有文件,以及后两个文件夹中的所有文件。 (而.DS_Store和*.log文件将在这些文件夹中被忽略。)

显然,我也可以执行!/folder或!/.gitignore 。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值