Capistrano上传.git目录

发布于 2024-09-14 16:47:52 字数 1453 浏览 3 评论 0原文

我正在将 git 与 capistrano 一起使用。

我在本地计算机上的文件夹中初始化了我的项目,如下所示:

git init

然后我将项目推送到服务器目录 然后我调用了cap deploy 部署工作正常,只是它将本地 .git 文件夹结构以及我的 .gitignore 和 Capfile 上传到可公开访问的文件夹。

这是我的 gitignore 文件:

.DS_Store
uploads/**/*
Capfile
.gitignore
.git/**/*

这似乎不起作用。有什么帮助吗?

谢谢!


编辑:更新了 .gitignore 文件:

将部署策略更改为导出:

set :deploy_via, :export

这适用于忽略 .git 文件夹,但仍然不考虑下面看到的 .gitignore 文件的内容

.DS_Store
includes/php/config.php
/uploads
Capfile
.git





编辑 2(解决方案): 编辑 1 结合以下内容就可以了。 在 .gitignore 文件中列出之前已添加的文件将不断上传。假设我有以下 .gitignore 文件。

.DS_Store
includes/php/config.php

然后我运行了以下命令:

git add .
git commit -a -m 'some commit'

然后我决定添加到我的 .gitignore 文件中,所以它现在看起来像这样:

.DS_Store
includes/php/config.php
Capfile

然后我再次运行:

git add .
git commit -a -m 'another commit'

现在我会看到 .DS_Storeincludes /php/config.php 尚未上传,但 Capfile 已...这就是我在最初的问题中发生的事情。 原因:我认为仅在添加时才考虑 .gitignore 文件(即 git add .)。如果我已经添加了文件,然后将它们放入 .gitignore 文件中,它们就已经添加到项目中了。我需要使用 git rm 命令来删除它们。 我刚刚使用新的 .git 存储库重新开始,这解决了问题,但您不必这样做 - 您可以删除已添加但现在想使用 git rm 命令忽略的任何文件。

我选择了帮助我得出这一结论的答案作为正确的答案,尽管完整的解决方案已在上面详细介绍。

I am using git with capistrano.

I initialized my project inside my folder on my local machine as such:

git init

I then pushed the project the server directory
I then called cap deploy
The deploy works, except that it uploads the local .git folder structure, as well as my .gitignore and Capfile to a publicly accessible folder.

Here's my gitignore file:

.DS_Store
uploads/**/*
Capfile
.gitignore
.git/**/*

This doesn't seem to do the trick. Any help?

Thanks!


Edit: updated .gitignore file:

Changed deployment strategy to export:

set :deploy_via, :export

This works for ignoring the .git folder, but the contents of my .gitignore file seen below are still not taken into account

.DS_Store
includes/php/config.php
/uploads
Capfile
.git





EDIT 2 (Solution): Edit 1 in combination with the following did the trick.
Files that were already added prior to being listed in the .gitignore file would constantly be uploaded. Say I had the following .gitignore file.

.DS_Store
includes/php/config.php

Then I ran the following commands:

git add .
git commit -a -m 'some commit'

Then I decided to add to my .gitignore file so it now looks like this:

.DS_Store
includes/php/config.php
Capfile

Then again, I ran:

git add .
git commit -a -m 'another commit'

Now I'd see that .DS_Store and includes/php/config.php have not been uploaded, but that the Capfile has... This is what happened to me in my original question.
The reason: I think the .gitignore file is taken into account only when adding (i.e. git add .). If I already added files, then put them in the .gitignore file, they would have already been added to the project. I'd need to use the git rm command to remove them.
I just started anew with a new .git repo and that solved the problem, but you don't have to - you can just remove whatever files you already added but now want to ignore with the git rm command.

I selected the answer that helped me get to this conclusion as the right one, though the complete solution was just detailed above.

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

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

发布评论

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

评论(2

像极了他 2024-09-21 16:47:52

您的部署策略是什么?

您是否有 Capistrano 设置来排除 .git 文件?
如果您使用 set :deploy_via, :copy,请确保添加以下内容:

set :copy_exclude, [".git/*", ".svn/*", ".DS_Store "]

否则使用 set :deploy_via, :export ,它应该忽略您的源代码管理文件夹

http://www.capify.org/index.php/Understanding_Deployment_Strategies

What is your deploy strategy?

Do you have Capistrano setup to exclude the .git file?
if you are using set :deploy_via, :copy then make sure to add the following:

set :copy_exclude, [".git/*", ".svn/*", ".DS_Store"]

Otherwise use set :deploy_via, :export which should ignore your source control folders

http://www.capify.org/index.php/Understanding_Deployment_Strategies

巾帼英雄 2024-09-21 16:47:52

查看类似问题,看来您不需要通配符选择器,并且可以:

uploads/

您需要通过 Capistrano 中的 :git 进行部署并进行导出。它本质上是一个 git 克隆,然后删除 .git 目录。

你的问题其实和Cap没有太大关系。确保您的 .gitignore 文件正常工作。

Looking at a similar question, it appears you don't need the wild card selectors and can just have:

uploads/

You need to deploy via :git in Capistrano and do an export. It's essentially a git clone and then just deletes the .git directory afterwards.

Your problem isn't much to do with Cap really. Make sure your .gitignore file is working correctly.

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