[英]How to manage changes of the app with different env with git branch?
I have a Rails app with two environments (staging and production)
. 我有一个具有两个环境
(staging and production)
的Rails应用程序。 I have my project in Bitbucket. 我在Bitbucket中有我的项目。 I have created a
branch (staging-branch)
from master
which I use for deploying
in staging environment. 我已经从
master
创建了一个branch (staging-branch)
,用于在staging环境中进行deploying
。
Once my staging works I would need to deploy the few of the changes from staging to production and not the whole changes that I made for the staging. 暂存工作完成后,我需要部署从暂存到生产的部分更改,而不是我为该暂存所做的全部更改。 In this case, if I create a
pull request
in bitbucket it takes all the files that were changed and adds it to be pulled from master. 在这种情况下,如果我在bitbucket中创建一个
pull request
,它将获取所有已更改的文件,并将其添加到要从主服务器中提取的文件中。
However, I want to move only certain files to the production. 但是,我只想将某些文件移到生产环境中。 How can I do this?
我怎样才能做到这一点? What approach should I follow for such cases?
在这种情况下我应该采取什么方法?
There are two approaches I would take to this. 我将采取两种方法。
The first, and preferable, one is to use proper, atomic feature- and hotfix branches. 第一个也是最好的选择是使用适当的原子特征和修补程序分支。 These would contain any and all changes required to implement a certain feature, or fix a certain issue.
这些将包含实现特定功能或解决特定问题所需的任何和所有更改。 Once you have merged this branch into
staging
and verified it works the way you want, you can simply merge the same branch into production
. 一旦将此分支合并到
staging
并验证了它可以按所需的方式工作,您就可以将同一分支合并到production
。
This requires a certain amount of diligence about keeping your commit history clean, and not mixing up different features or fixes in the same branch. 这需要一定的工作量,以保持提交历史记录的整洁,并且不要混淆同一分支中的不同功能或修补程序。
At work, we use GitHub Flow with great results: https://guides.github.com/introduction/flow/ 在工作中,我们使用GitHub Flow取得了不错的效果: https : //guides.github.com/introduction/flow/
The second one, if you are developing directly on the staging
branch, is to create a new branch and use git cherry-pick
to select only the changes that you want to go into production
, and then merge this new branch in. 如果直接在
staging
分支上进行开发,则第二个是创建一个新分支,并使用git cherry-pick
仅选择要投入production
的更改,然后将该新分支合并到其中。
Here is the manual for git cherry-pick
: http://git-scm.com/docs/git-cherry-pick 这是
git cherry-pick
的手册: http : //git-scm.com/docs/git-cherry-pick
The latter one certainly feels like a hack, and might give you problems with keeping track of how staging
and production
have diverged--and although I would not suggest it as a permanent solution, I included it as an option that can be used to solve your immediate problem. 后者肯定感觉像是黑客,并且可能会给您带来有关
staging
和production
差异的问题-尽管我不建议将其作为永久解决方案,但我将其作为可用于解决问题的选项您当前的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.