Capistrano上传.git目录
我正在将 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_Store
和 includes /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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的部署策略是什么?
您是否有 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 foldershttp://www.capify.org/index.php/Understanding_Deployment_Strategies
查看类似问题,看来您不需要通配符选择器,并且可以:
您需要通过 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:
You need to deploy via
:git
in Capistrano and do an export. It's essentially agit 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.