Home > Net >  Is it possible to deploy some changes from one git branch to other?
Is it possible to deploy some changes from one git branch to other?

Time:11-17

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. 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. Currently, I have my changes in QA branch is there any way to deploy only my changes from QA to PRD. I don't want to overwrite other developer's change in QA.

CodePudding user response:

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. 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:-

-List the commits on the QA branch:-

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:-

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
  • Related