如何 gitignore 除了目录之外的所有内容?

发布于 2024-09-11 09:06:42 字数 317 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

玩世 2024-09-18 09:06:44

什么对我有用:

# Ignore every directory
/*
# Except this one
!/test

或者

# Ignore every file
*
# Except these ones
!test
!test/*
!test/*/*

What works for me:

# Ignore every directory
/*
# Except this one
!/test

Or

# Ignore every file
*
# Except these ones
!test
!test/*
!test/*/*

有深☉意 2024-09-18 09:06:44

尝试:

!test/*

相反。我不确定这是否有效(疯狂猜测),但值得一试。

Try:

!test/*

instead. I'm not sure if this will work (wild guess), but it is worth a try.

橘和柠 2024-09-18 09:06:44
$ cat .gitignore
**/*
*
# test is a directory
!test
$ cat .gitignore
**/*
*
# test is a directory
!test
梅倚清风 2024-09-18 09:06:43

从我的主目录中的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文