简体   繁体   English

是否可以将一些更改从一个 git 分支部署到其他分支?

[英]Is it possible to deploy some changes from one git branch to other?

In my organization we use a pattern where developers will create a new branch merge it to dev then, merge dev to qa and qa to prd.在我的组织中,我们使用一种模式,开发人员将创建一个新分支,将其合并到 dev,然后将 dev 合并到 qa,将 qa 合并到 prd。 Now, I have situation that some other developer did some changes to QA and he don't want to deploy his changes to prd yet.现在,我的情况是其他一些开发人员对 QA 做了一些更改,但他不想将他的更改部署到 prd。 Currently, I have my changes in QA branch is there any way to deploy only my changes from QA to PRD.目前,我在 QA 分支中有我的更改,有什么方法可以仅将我的更改从 QA 部署到 PRD。 I don't want to overwrite other developer's change in QA.我不想覆盖其他开发人员在 QA 中的更改。

As knittl said, this depends on your policies in the company so it is very important that you ask the lead/manager of your team before attempting to do anything.正如 knittl 所说,这取决于您在公司的政策,因此在尝试做任何事情之前询问您团队的领导/经理非常重要。 That being said, from a technical standpoint this is completely doable.话虽如此,从技术角度来看,这是完全可行的。 First you need to copy the git hashes of the commits you want to cherry-pick as follows:-首先,您需要复制要挑选的提交的 git 哈希值,如下所示:-

-List the commits on the QA branch:- -列出 QA 分支上的提交:-

git log --oneline qa-branch

This will give you the list of hashes, something along the lines of:这将为您提供哈希列表,大致如下:

aabbccdd commit 7
00112233 commit 6
44556677 commit 5
abcd1234 commit 4

Now let's say you want to copy over the 4th and 5th commit, then you do this as follows:-现在假设您想复制第 4 次和第 5 次提交,然后按如下方式执行此操作:-

git checkout prod-branch git cherry-pick abcd1234 git cherry-pick 44556677 git checkout prod-branch git cherry-pick abcd1234 git cherry-pick 44556677

You can try to be even more safe and create backup branch to do your work there, build the code to make sure everything works, then merge things to your main prod branch.您可以尝试更加安全并创建备份分支以在那里完成您的工作,构建代码以确保一切正常,然后将内容合并到您的主要产品分支。 The workflow would be like this:-工作流程将是这样的:-

git checkout prod-branch
git checkout -b prod-branch-backup
git cherry-pick abcd1234
git cherry-pick 44556677
#Build project and run tests
git checkout prod-branch
git merge prod-branch-backup

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

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