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

查看:118
本文介绍了如何在.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

推荐答案

这2个文件大多是正交的,它们具有不同的用途,并且由不同的工具使用.

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

它们之间的唯一关系(除了.gcloudignore很大程度上继承了.gitignore语法和行为)是将.gitignore文件包含在.gcloudignore文件中的能力,这是您要做的:

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

当然,这样做的副作用是,在GAE部署期间,.gitignore中的一切也将被忽略,正如您所观察到的.来自 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

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:

  • 仅保留在部署时也要忽略的文件模式(当然,请保留.gcloudignore中的.gitignore)
  • 将其他模式放在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天全站免登陆