[英]How do you gitignore everything except a directory?
I am trying to sync my desktop and laptop using a cron'd git. 我正在尝试使用cron'd git同步我的台式机和笔记本电脑。 It works beautifully on a single directory.
它在单个目录上可以很好地工作。 However I want to sync multiple config files scattered about and some other things.
但是我想同步分散的配置文件和其他一些东西。 To do this decided to turn my home folder into a git directory and ignore everything except for a few select files and directories.
为此,决定将我的主文件夹转换为git目录,并忽略除几个选择文件和目录之外的所有内容。
$ cat .gitignore
*
# test is a directory
!test
Does not work. 不起作用。 Looking at another stackoverflow question, I found
*/
and used it instead of *
. 看着另一个stackoverflow问题,我发现
*/
并用它代替*
。 That almost worked as I wanted it to, but then all of the random single hidden files I have scattered about my home directory showed up. 这几乎可以按我的意愿工作,但是随后出现了我散布在主目录中的所有随机单个隐藏文件。
What works for me: 什么对我有用:
# Ignore every directory
/*
# Except this one
!/test
Or 要么
# Ignore every file
*
# Except these ones
!test
!test/*
!test/*/*
From my git ignore in my home directory. 从我的git忽略我的主目录。
*
*
Then you have to git add -f
stuff you want to commit. 然后,您必须
git add -f
您要提交的东西。 Least that is how I do it for my configs. 至少这就是我为配置执行的操作。
Try: 尝试:
!test/*
instead. 代替。 I'm not sure if this will work (wild guess), but it is worth a try.
我不确定这是否行得通(疯狂猜测),但是值得一试。
$ cat .gitignore
**/*
*
# test is a directory
!test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.