如何 gitignore 除了目录之外的所有内容?
我正在尝试使用 cron'd git 同步我的台式机和笔记本电脑。它在单个目录上运行得很好。不过,我想同步分散的多个配置文件和其他一些东西。为此,我决定将我的主文件夹转换为 git 目录,并忽略除一些选定文件和目录之外的所有内容。
$ cat .gitignore
*
# test is a directory
!test
不起作用。查看另一个 stackoverflow 问题,我发现 */
并使用它而不是 *
。这几乎按照我想要的方式工作,但是随后我分散在主目录中的所有随机单个隐藏文件都出现了。
I am trying to sync my desktop and laptop using a 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.
$ cat .gitignore
*
# test is a directory
!test
Does not work. Looking at another stackoverflow question, I found */
and used it instead of *
. 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
什么对我有用:
或者
What works for me:
Or
尝试:
相反。我不确定这是否有效(疯狂猜测),但值得一试。
Try:
instead. I'm not sure if this will work (wild guess), but it is worth a try.
从我的主目录中的 git 忽略。
然后你必须
git add -f
你想要提交的东西。至少我的配置就是这样做的。From my git ignore in my home directory.
Then you have to
git add -f
stuff you want to commit. Least that is how I do it for my configs.