问个.gitignore的问题

2012-01-06 15:41:06 +08:00
 yesmeck
我有这样一个git目录

.
|-- README
`-- template
...`-- compiled
........|-- admin
........|...|-- haha
........|...`-- index.html
........|-- haha
........`-- index.html

现在需要把template这个目录里除了两个index.html外都忽略掉

master* $ cat .gitignore
template/compiled/*
!template/compiled/index.html
!template/compiled/admin/index.html

上面那样写的话template/compiled/admin/index.html这个文件还是会被忽略掉

请教各位正确的写法
4313 次点击
所在节点    问与答
7 条回复
yesmeck
2012-01-06 15:44:47 +08:00
master* $ cat .gitignore
template/compiled/*
!template/compiled/admin/
!template/compiled/index.html
template/compiled/admin/*
!template/compiled/admin/index.html

发现这样写是可以,但是应该不用这么复杂吧。。。。
coupgar
2012-01-06 15:44:50 +08:00
*/index.html 试试
yesmeck
2012-01-06 15:47:00 +08:00
@coupgar
template/compiled/*
!template/*/index.html

这样写admin下面的还是会被忽略掉
9hills
2012-01-06 16:44:08 +08:00
在template下新建.gitignore:
/*¬
!/.gitignore
!/index.html
!/admin

然后再在admin目录下新建 .gitignore
/*
!/.gitignore
!/index.html

这种情形用子目录的.gitignore比全局要方便。
9hills
2012-01-06 16:46:50 +08:00
补充一下,上面的第一个/*后多了一个符号“¬”,请删掉。
然后这种方法多用于git添加空目录。。只需要前两行
/*
!/.gitignore
kaichen
2012-01-06 16:57:23 +08:00
@yesmeck

用*/index.html,然后用git add -f把需要的那两个加进来,这样不折腾。
yesmeck
2012-01-06 17:08:46 +08:00
@9hills

OK,就这么做了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/25092

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX