0

I have a development branch called main, a staging branch called staging and production branch called production. I want to push a hotfix to production branch.

First I created a new branch off main:

git checkout main
git checkout -b hotfix

Then I merged the branch to main:

git checkout main
git merge hotfix

then merged the branch to staging in order to deploy first to staging environment and check that the branch works:

git checkout staging
git merge hotfix

Now I want to merge the hotfix branch to production however merging brings a lot of other changes not-related to the hotfix. These other changes were not checked in staging environment yet so I don't want to have them in production. Therefore I decided to just cherry-pick the commits related to the hotfix from the hotfix branch into production. I also had some conflicts when cherry-picking.

I'm wondering though if in the future there will be changes to the regions of code which I cherry-picked in main and staging, will they be reflected in production? I'm afraid that git will not reflect them because of the cherry-pick and conflicts.

Is there a better way to handle hotfixes in git so that the above issues don't occur?

hitchhiker
  • 1,099
  • 5
  • 19
  • 44
  • Show a diagram for your graph. – Mad Physicist Apr 13 '21 at 09:24
  • Cherry-pick makes a new commit based on some existing commit. That's pretty much it. Is a new commit *divergent* history? That depends on how you define "divergent". History is commits; commits are history; but "divergent" is in the eye of the beholder. – torek Apr 13 '21 at 09:31

1 Answers1

0

I'm not sure I understand your question correctly, but about this part:

I'm wondering though if in the future there will be changes to the regions of code which I cherry-picked in main and staging, will they be reflected in production? I'm afraid that git will not reflect them because of the cherry-pick and conflicts.

When you cherry-pick, git "replays" the changes that commit introduced, and apply those changed on the target branch, making a new (and different) commit. This commit has no links to the one you cherry-picked, so Git will never be aware of anything that happens on the "other side", conflicts resolution or not.