Domanda

I am working on a project with a Master branch, of course :P and multiple release branches created over time. The version control I'm using is Git and I was looking for a way to apply bug fixes (for example) made in one release branch to the others, automatically if possible. I.e...

--------------------------Master
|      |        |__v3
|      |__v2
|___v1
  |____bugfix

If I fix a bug found in v1, and need to apply the same fix (and only the fix) in v2 and v3, is there a way I can do this conveniently in Git?

I am new to Git but thought I might be able to Chery-pick the commit and apply it, but I was wondering if the branches need to be directly related in the hierarchy? Is it possible to cherry-pick or perhaps rebase from 'bugfix' under v1 to v2 and v3? (or v3 to v2 etc) Afaik, rebase will replay all commits, so I think cherry-pick is what im looking for, but I am unsure how to achieve this. Posts I have seen cherry-pick from child to parent branch. Is what im trying to do possible?

Cheers.

È stato utile?

Soluzione

If the bugfix is a single commit, or a range of commits you can use cherry pick.

Your bugfix would be one commit and the sha is SHA1

git checkout v2
git cherry-pick SHA1

If it's several commits, find the commit sha before the first commit of the bugfix, SHA1, and the last commit sha of the bugfix SHA2

git checkout v2
git cherry-pick SHA1..SHA2
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top