Git工作流程与Capistrano [英] Git Workflow With Capistrano

查看:177
本文介绍了Git工作流程与Capistrano的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图用capistrano把我的头放在一个很好的git工作流上。我发现一个几个 good 文章,但我不是完全掌握他们的建议(可能)有点缺乏。



这是我到目前为止所记住的一切,但是我被抓到了什么时候合并回主分支(即在转入舞台之前?之后),然后尝试将其挂钩到capistrano进行部署:


  1. 确保您掌握最新的所有更改其他开发商的远程主分支


    • git checkout master

    • git pull


  2. 创建一个与特定错误相关的新分支试着去修复


    • git checkout -b bug-fix-branch


  3. 进行更改


    • git status

    • git add。

    • git commit -m友好关于提交的消息


所以,通常是我被卡住的地方。在这一点上,我有一个健康的主站分支和一个包含我的(未经测试的 - 除单元测试)更改之外的新的错误修复分支



如果我想将我的更改推送到舞台(通过 cap staging deploy ),我必须将我的更改合并进入主分支(我不喜欢,因为似乎主人应该没有未经验证的代码)?我甚至从主管部署(或者我应该首先标记一个版本,然后修改我的 production.rb 文件以从该标签部署)? git-deployment 似乎解决了这些工作流程中的一些问题,但我似乎找不到如何在地球上实际上挂钩进入帽阶段部署和上限生产部署。



想法?我认为有可能规范的方法来做到这一点,但是我或者不能找到它,或者我太新,不能认出我发现它。



帮助!

解决方案

我所做的就是在你的祝福的回购中追踪一个分期分支。您将需要使用gem'capistrano-ext',它为阶段提供了一些额外的配置选项(我认为您已经在考虑使用这个选项来部署在分段上)。 capistrano-ext 定义阶段,它允许您为每个阶段配置一个部署文件,例如staging,您定义分支 set:branch, 分段您正在部署的每个阶段都是唯一的。您可以在上面的工作流程中添加:

  #after提交错误修复分支
git checkout staging#= >跟踪起始原点
git merge bug-fix-branch#=>带来新代码
git push origin staging#=> capsitrano在本地执行,它需要从源代码获取
cap staging deploy#=>不是那么容易吗

在一个理想的世界中,你也有一个生产分支,所以git分支被团队作为




  • 主人 - 边缘代码,团队
    在开发者之间共享

  • - 由
    客户端在分段服务器上测试的代码
    (主合并快进)

  • 生产 - 稳定版本
    (fastforwards from分享)



编辑:对评论的回复时间太长,所以我不得不追加到答案。



你有几种方法来处理这个,我可以立即想到一个。需要在所有分支机构中反映出对prod的修复,所以您的开发人员正在同一个基础上工作。假设prod有一个直接共同的祖先进行分期,并且分阶段掌握,prod的修复应该被添加到在prod分支的HEAD之外的主题分支,然后将该更改与master并入然后进入分段,最后部署到生产。这个想法是唯一的差异是错误修复的提交,下一次将生产快速转到头部进行分期时,您已经有了代表您修复的prod bug的更改的对象,因此没有问题(因为有一个很好的测试,你知道它的工作原理,每个分支上运行套件后)。否则你可能不得不从主人那里挑选一个提交,并应用于生产和分期。看一下这样的更高级的工作流程,这个程序可以在这里使用。


I'm trying to get my head around a good git workflow using capistrano. I've found a few good articles, but I'm either not grasping completely what they're suggesting (likely) or they're somewhat lacking.

Here's kind of what I had in mind so far, but I get caught up when to merge back into the master branch (i.e. before moving to stage? after?) and trying to hook it into capistrano for deployments:

  1. Make sure you’re up to date with all the changes made on the remote master branch by other developers
    • git checkout master
    • git pull
  2. Create a new branch that pertains to the particular bug you're trying to fix
    • git checkout -b bug-fix-branch
  3. Make your changes
    • git status
    • git add .
    • git commit -m "Friendly message about the commit"

So, this is usually where I get stuck. At this point, I have a master branch that is healthy and a new bug-fix-branch that contains my (untested -- other than unit tests) changes.

If I want to push my changes to stage (through cap staging deploy), do I have to merge my changes back into the master branch (I'd prefer not to since it seems like master should be kept free of untested code)? Do I even deploy from master (or should I be tagging a release first and then modifying my production.rb file to deploy from that tag)? git-deployment seems to address some of these workflow issues, but I can't seem to find out how on earth it actually hooks into cap staging deploy and cap production deploy.

Thoughts? I assume there's a likely canonical way to do this, but I either can't find it or I'm too new to git to recognize that I have found it.

Help!

解决方案

The way that I do it is to have a 'staging' branch that is tracked on your blessed repo. You will want to use the gem 'capistrano-ext' which provides a few extra config options for stages (I think you are already using this considering your call to deploy on staging). capistrano-ext defines stages, which allows you to have a deploy file for each stage, eg 'staging' where you define the branch set :branch, "staging" unique to each stage you are deploying to. You can do your workflow above and add:

#after commiting on bug-fix branch
git checkout staging # => tracks staging on origin
git merge bug-fix-branch # => bring new code in
git push origin staging # => capsitrano acts locally, it needs the code to get from origin
cap staging deploy # => wasnt that easy?

in an ideal world, you also have a production branch, thus the git branches become agreed upon by the team as

  • master - edge code where the team shares between devs
  • staging - code to be tested by the client on a staging server (fast-forwards on master merge)
  • production - stable release (fastforwards from staging)

EDIT: the response to the comment was too long so i had to append to the answer.

You have several ways to deal with this, I can think of one right away. A fix on prod needs to be reflected in all branches asap so your devs are working on the same base. Assuming prod has a direct common ancestor to staging, and staging to master, a fix on prod should be added to a topic branch based off the HEAD of the prod branch, then merge that change with master and then into staging and finally for deploy into production. The idea is that the only diff is the commits for the bug fix, next time you fast-forward production to the head on staging, you would already have the object that represents the change from the prod bug you fixed, so there is no problem (and since there is good testing for the bug you know it works, after running the suite on each branch). Otherwise you would probably have to cherry-pick a commit from master and apply to prod and staging. Take a look at pro-git.org for more advanced workflows like that.

这篇关于Git工作流程与Capistrano的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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