简体   繁体   English

Git在测试环境上分支

[英]Git branching on test environment

I started working on a company that newly using git. 我开始在一家刚使用git的公司工作。 I need a good recommendation. 我需要一个很好的建议。 First, I would like to talk about current workflow. 首先,我想谈一谈当前的工作流程。

The team's workflow is pretty much different than regular git basis. 团队的工作流程与常规git基本有很大不同。 The branches are 分支机构是

Local (feature/hotfix branch from Dev) -> Dev -> Test -> Prod

The environments 环境

Dev -> Test -> Prod
  1. Each branch have different config files (No solution for that yet. But I will fix this issue first) therefore, we can't merge the branches. 每个分支都有不同的配置文件(尚无解决方案。但是我将首先解决此问题),因此,我们无法合并分支。
  2. Developers are working on Local (feature/hotfix branch) and merge their pushes into the Dev branch and publish their versions on Dev environment (just patch version is increasing (1.0.xxx), I know it is not good thing to do.) 开发人员正在使用Local(功能/修补程序分支),并将其推入合并到Dev分支中,并在Dev环境中发布其版本(只是补丁版本不断增加(1.0.xxx),我知道这样做不是一件好事。)
  3. And then they cherry-pick their changes into the Test branch. 然后他们将所做的更改挑选到Test分支中。 And, they publish a new version on the test environment. 并且,他们在测试环境上发布了新版本。 UAT is happining here. UAT在这里令人陶醉。
  4. When the developers want to publish their changes into production environment they also cherry-pick their changes. 当开发人员想要将他们的更改发布到生产环境中时,他们还会选择更改。 And publish a new version on prod environment. 并在产品环境中发布新版本。

First problem here, we can't observe the branches' history very well because we can't merge the branches due the config files. 这里的第一个问题是,由于配置文件的原因,我们无法合并分支,因此我们无法很好地观察分支的历史。

Second problem is some of the changes should stay on test environment 1-2 two weeks, changes can have a long or short lifetime. 第二个问题是,某些更改应在测试环境1-2上停留两周,更改可能具有长寿命或短寿命。

Third problem, we can't use git features like merge and pull request. 第三个问题,我们不能使用git特性,例如合并和拉取请求。 We want to use PR for code review and so on. 我们想使用PR进行代码审查等等。 It is important for us. 这对我们很重要。

I can say the deployment process and version control system are mixed in this scenario. 我可以说在这种情况下,部署过程和版本控制系统是混合的。 Therefore, we would like to use something like git-flow. 因此,我们想使用git-flow之类的东西。 Although, we want to keep that three environments (dev, test and prod) and main goal is merging the branches and using the pull requests 虽然, 我们希望保留这三个环境(开发,测试和生产),并且主要目标是合并分支并使用拉取请求

Let's say, we have only develop and master branches. 假设,我们只有开发和掌握分支机构。 Developers work on feature branches. 开发人员在功能分支上工作。 And merge their features into develop.Next, we created a release branch for test environment. 并将其功能合并到开发中。接下来,我们为测试环境创建了一个发布分支。 But what we should do for different lifetime change-sets ? 但是,我们应该为不同的生命周期变更集做什么呢?

How we should merge the release branches into master branch ? 我们如何将发布分支合并到master分支中? How we should handle the test environment on git branches ? 我们应该如何在git分支上处理测试环境?

For example; 例如;

release 1.3.0 - have a feature that should stay 2 weeks on test environment and then should go for production environment release 1.3.0 -具有一项功能,应在测试环境中保留2周,然后再进入生产环境

release 1.4.0 - someone added a new feature that should go for production environment in a couple of days. release 1.4.0 -有人添加了一项新功能,应在几天内用于生产环境。 (while release 1.3.0 is still alive.) (虽然release 1.3.0仍然有效。)

So, test environment will have that two features and prod should have the latest one after a couple of days. 因此,测试环境将具有这两个功能,并且产品在几天后应具有最新的功能。 But the release 1.4.0 branch have the both features. 但是release 1.4.0分支具有这两个功能。 What should I merge into production branch ? 我应该将什么合并到生产分支中?

Should we use different thing than git-flow ? 我们应该使用不同于git-flow的东西吗? what is your recommendation ? 您有什么建议?

That was a lot of different questions. 那是很多不同的问题。 I'll try to answer the one I think is most important. 我将尝试回答我认为最重要的问题。

Your existing workflow sounds inspired by something like subversion, where it is common to avoid merging by instead cherry-picking. 您现有的工作流程听起来像是颠覆之类的东西,在这种情况下,通常避免通过采摘来避免合并。 In git the preference is definitely to merge. 在git中,首选绝对是合并。

The main reason you give for not merging the branches is that you want to keep config files different. 您给出的不合并分支的主要原因是您想使配置文件保持不同。 But that is not as big a problem as you seem to think. 但这并不是您似乎想的那样大的问题。

Say that you have a config file config.json in Dev and one with a different content in Test . 假设您在Dev有一个配置文件config.json ,而在Test有一个不同的内容。

You can do this 你可以这样做

# register a merge driver named 'ours' that uses the command 'true' to always return 0
git config --global merge.ours.driver true

git checkout Dev
echo 'config.json merge=ours' >> .gitattributes
git add .gitattributes
git commit -m 'Preserve config.json during merges'

git checkout Test
# copy the same commit, since we want the same setting in all branches
git cherry-pick Dev

# now, when you merge, config.json will be ignored
git merge Dev

Full example here 完整的例子在这里

So, this should make it possible to merge branches, which should solve your first and second problem. 因此,这将使合并分支成为可能,这将解决您的第一个和第二个问题。 Adding PRs to this should also work, solving your third problem. 向此添加PR也应该可行,从而解决您的第三个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM