Git 忽略除子文件夹之外的所有内容

发布于 2024-11-28 14:34:15 字数 393 浏览 1 评论 0原文

我搜索了其他问题,但找不到适合我的项目的可行解决方案。 拥有一个 Magento 项目,我想排除除此之外的所有内容:

/app/design/frontend/default/theme_name # and obviously all subfolders
/skin/frontend/default/theme_name # and all subfolders

我尝试了很多组合,但没有运气。目前我被这个 .gitignore 文件困住了:

*
!/app/
!/app/*

app/*
!/app/design/
!/app/design/*

但它不能在设计文件夹下递归地工作。它仅在我创建的设计文件夹中添加了一个测试文件。

I searched through other questions but can't find a working solution for my project.
Having a Magento project, I want to exclude everything except this:

/app/design/frontend/default/theme_name # and obviously all subfolders
/skin/frontend/default/theme_name # and all subfolders

I've tried a lot of combinations but without luck. Currently I'm stuck with this .gitignore file:

*
!/app/
!/app/*

app/*
!/app/design/
!/app/design/*

But it doesn't work recursively below the design folder. It only added a test file inside the design folder that I created.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

云醉月微眠 2024-12-05 14:34:15

在这里看看我的答案: 无法理解 gitignore 如何忽略文件夹

引用:

以下讨论很有帮助:
http://git.661346。 n2.nabble.com/neated-list-in-gitignore-no-fun-td1675067.html
,尤其是 Linus 的以下内容:

这是设计使然。您选择忽略这些目录;他们
匹配“*”本身。因此,“git add”。不会降临到他们身上
寻找文件。

所以基本上,对于你必须进入的每个级别,不要忽略该文件夹,
并忽略该文件夹中的内容。

另外,您应该考虑将 .gitignore 放在子目录而不是根级别,因为如果您必须从根 .gitignore 转到子目录级别,它会变得非常复杂由于上面的解释,对于每个级别,您都必须忽略文件夹,然后忽略内容等等。

Look at my answer here: Can't understand how gitignore ignores the folders

Quoting from that:

The following discussion was helpful:
http://git.661346.n2.nabble.com/negated-list-in-gitignore-no-fun-td1675067.html
, especially the following from Linus:

That's by design. You've chosen to ignore those directories; they
match "*" themselves. Thus, 'git add .' doesn't descend into them
looking for files.

So basically, for each level you have to go in, unignore that folder,
and ignore contents within that folder.

Also, you should look at having .gitignore at subdirectory rather than at root level only as it becomes pretty complex if you have to go to the subdirectory level from the root .gitignore because of the explanation above, whereby for each level, you have to unignore the folder and then ignore the contents and so on.

梦归所梦 2024-12-05 14:34:15

在这里做了一些研究。对我有用的是:

/*
!/directory
!/another
/another/*
!/another/directory

通过这个 /directory 的子目录可以正确跟踪。奇怪的是,它不适用于第一行上的仅 / 或仅 * - 我不知道为什么。

Did some research here. What worked for me was:

/*
!/directory
!/another
/another/*
!/another/directory

With this subdirectories of /directory were tracked correctly. Curiously it doesn't work with either only / or only * on the first line - I am not sure why.

拥抱影子 2024-12-05 14:34:15
/**
!/**/
!/app/design/frontend/default/theme_name/**
!/skin/frontend/default/theme_name/**

说明:

  1. 递归地忽略所有文件和文件夹(注意双星号)。
  2. 递归地排除所有文件夹(git 按设计不会提交空文件夹,其中充满被忽略文件的文件夹被算作。我们需要这个,以便接下来的两个排除工作)
  3. 从此位置递归地排除所有文件和文件夹。
  4. 从此位置递归排除所有文件和文件夹。

我通常对子文件夹执行此操作,所以我不知道第一行是否有效。

/**
!/**/
!/app/design/frontend/default/theme_name/**
!/skin/frontend/default/theme_name/**

Explaination:

  1. ignore all files and folders, recursively (note the double asterisk).
  2. exclude all folders, recursively (git by design will not commit empty folders, which a folder full of ignored files is counted as. We need this so that the next two excludes work)
  3. exclude all files and folders, recursively, from this location.
  4. exclude all files and folders, recursively, from this location.

I usually do this to sub-folders, so I don't know if the first line will work.

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