[英]How do I ignore everything except a couple files in the top-level directory and everything in a few directories with .gitignore
[英]How do you gitignore everything except a directory?
我正在尝试使用cron'd git同步我的台式机和笔记本电脑。 它在单个目录上可以很好地工作。 但是我想同步分散的配置文件和其他一些东西。 为此,决定将我的主文件夹转换为git目录,并忽略除几个选择文件和目录之外的所有内容。
$ cat .gitignore
*
# test is a directory
!test
不起作用。 看着另一个stackoverflow问题,我发现*/
并用它代替*
。 这几乎可以按我的意愿工作,但是随后出现了我散布在主目录中的所有随机单个隐藏文件。
什么对我有用:
# Ignore every directory
/*
# Except this one
!/test
要么
# Ignore every file
*
# Except these ones
!test
!test/*
!test/*/*
从我的git忽略我的主目录。
*
然后,您必须git add -f
您要提交的东西。 至少这就是我为配置执行的操作。
尝试:
!test/*
代替。 我不确定这是否行得通(疯狂猜测),但是值得一试。
$ cat .gitignore
**/*
*
# test is a directory
!test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.