如何在 .gcloudignore 中包含在 .gitignore 中被忽略的文件 [英] How to include files in .gcloudignore that are ignored in .gitignore

查看:30
本文介绍了如何在 .gcloudignore 中包含在 .gitignore 中被忽略的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 .gitignore 中忽略了某些文件夹,因为我不希望它在 Github 上发布.

I have certain folders that I ignore in my .gitignore as I do not want it to be published on Github.

但是,这些文件在部署到 Google Cloud(本地包)时必不可少.

However, these files are essential for when deploying to Google Cloud (local packages).

如果我从 .gcloudignore 中取出 .gitignore 那么我想要忽略的文件(比如 venv, .idea, .pyc>) 上传,这是我不想要的.

If I take out .gitignore from .gcloudignore then the files that I do want to ignore (like venv, .idea, .pyc) are uploaded, which is what I do not want.

如何在 .gcloudignore 中只包含 .gitgnore 的一部分?

How can I there include only a portion of .gitgnore in .gcloudignore?

.gcloudignore

.gcloudignore
.git
.gitignore

node_modules
#!include:.gitignore

.gitignore

# This I want to ignore in .gcloudignore
.Python
env/
build/

# This I want to keep in .gcloudignore
module_data_import
module_calendar

推荐答案

这两个文件大多是正交的,它们服务于不同的目的,被不同的工具使用.

The 2 files are mostly orthogonal, they serve different purposes and are used by different tools.

它们之间的唯一关系(除了从 .gitignore 语法和行为中大量继承的 .gcloudignore 之外)是能够包含 .gitignore.gcloudignore 文件中的 code> 文件,这就是您要做的:

The only relationship between them (apart from .gcloudignore inheriting heavily from the .gitignore syntax and behaviour) is the ability to include the .gitignore file inside the .gcloudignore file, which is what you do with:

#!include:.gitignore

当然,它的副作用是,.gitignore 中的 一切 在 GAE 部署期间也将被忽略,正如您所观察到的.来自 gcloud 主题 gcloudignore:

The side effect of that is, of course, that everything in .gitignore will also be ignored during GAE deployments, as you observed. From gcloud topic gcloudignore:

这将包括 .gitignore 样式文件的内容文件中该点的路径.它不会递归(即包含文件 cannot #!include 另一个文件)并且不能除了要上传的顶级目录之外的任何地方.

This will include the contents of a .gitignore-style file at that path at that point in the file. It does not recurse (that is, the included file cannot #!include another file) and cannot be anywhere but the top-level directory to be uploaded.

但是您不必包含.gitignore.您需要做的就是删除该包含,并仅指定要在部署中忽略的 .gitignore 中的模式.如果我正确理解您的目标描述,.gcloudignore 将如下所示:

But you don't have to include .gitignore. All you need to do is drop that inclusion and specify exactly just the patterns from .gitignore that you want to ignore in deployments. If I understand correctly your goal description the .gcloudignore would look something like this:

.gcloudignore
.git
.gitignore

node_modules
module_data_import
module_calendar

如果在两个文件中复制这些模式让您感到困扰,那么一个潜在的替代方案(恕我直言相当复杂)可能是利用 git 的能力来忽略基于从多个来源(具有不同范围,不过,请注意这一点).请参阅 https://git-scm.com/docs/gitignore我可以在其中包含其他 .gitignore 文件吗.gitignore 文件?(就像在类似 c 的语言中的 #include).

If duplicating those patterns in both files bothers you a potential alternative (IMHO rather complex) might be to take advantage of git's ability to ignore files based on patterns collected from multiple sources (with different scopes, though, so pay attention to that). See https://git-scm.com/docs/gitignore and Can I include other .gitignore file in a .gitignore file? (like #include in c-like languages).

如果您能找到适合您的应用程序的合适拆分,您可以:

If you can find a proper split fitting your application you could:

  • 保留 .gitignore 只是您在部署时也想忽略的文件模式(当然,保留 .gitignore 包含在 .gcloudignore)
  • 将其他模式放在 git 用来确定忽略规则的另一个文件中 - 因此它们会被 git 忽略,但由于此文件未包含在 .gcloudignore 中,因此它们不会被忽略部署.
  • keep in .gitignore just the patterns for files that you also want to ignore at deployments (keeping, of course, the .gitignore inclusion in .gcloudignore)
  • place the other patterns in another file that git uses to determine ignore rules - thus they'd be ignored by git but since this file isn't included in .gcloudignore they would not be ignored at deployments.

更新以下评论:

在最初的回答中,我没有考虑 gcloud 命令本身执行直接或间接针对源代码存储库操作的操作的情况,如果使用 git 作为版本控制系统,当然会,受 .gitignore 文件的存在和内容的影响.在这种情况下,可以认为 gcloud 命令本身使用 .gitignore 文件(无论 .gcloudignore 文件如何).

In the initial answer I didn't consider the case in which the gcloud command itself executes operations that target directly or indirectly source code repository operations under the hood which, if using git as the version control system, will be, of course, impacted by the presence and content of the .gitignore file. In such case one could arguably consider that the gcloud command itself uses the .gitignore file (regardless of the .gcloudignore file).

这篇关于如何在 .gcloudignore 中包含在 .gitignore 中被忽略的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆