Question

I am assigned to two projects, both of which are derived from a common parent and targeted to be merged back to the parent around the same time. To make it simple, let's call them master, projA and projB.

Let's say the folder structure of the source code is:
/src/main/UI
/src/main/backend

Let's say there is a file and we want to add a new common error handler inside of it.
This function should be shared between projA and projB.
/src/main/backend/common/errorhandler.cpp

The branching is as follows (both branched from master and ultimately merged back to master. aN/bN are project specific changes. AN/BN are changes errorhandler.cpp

       -- projA--a1-a2--A1--
      /                     \
------                       master
      \                     /
       -- projB--b1-b2--B1--

So at some point there may be changes in projA that are needed in projB, so the commits would look like this (say after cherry-picking A1 into projB).

       -- projA--a1-a2--A1--a3---
      /                          \
------                            master -- projA' -- projB'
      \                          /
       -- projB--b1-b2--B1--A1'--

From what I read, I cannot merge just A1 into projB. It would merge a1, a2, and A1.

I could use cherry-pick, which would then be A1' in projB, at the expense having A1` and A1 being treated as separate changes when both projA and projB are merged back to master.

I was hoping someone might have a better plan where I could still use merge so that I do not end up with 'duplicate' changes.

Était-ce utile?

La solution

EDIT:

First (just to make sure), your /src/main/backend/common/ should be implemented in the master branch (and maybe edited in any branch).

Then you create your branches projA and projB from master. You work on projA branch on the UI, and at the same time on the backend in projB branch. No problem so far.

You have now A1, B1 commits in respective branches.

      ---projA -- a1 -- a2 -- A1 
     /                          
----------------------------- master
     \                          
      ---projB -- b1 -- b2 -- B1

And what you want is only A1,B1 but not a1, a2, b1, b2. Indeed I recommend cherry-pick. One bad thing (among others) with cherry-pick is that the history is not nice afterwards. But in your case, I don't see many (even any) other possibilities.

When you are on master branch (to switch: git checkout master), you run git cherry-pick A1 (A1 being the commit SHA) and it will merge the UI commit 'A1' into master branch:

      ---projA -- a1 -- a2 -- A1    
     /                             
------------------------- master ---- A1'
     \                          
      ---projB -- b1 -- b2 -- B1

and then, still on master branch, you merge the backend commit 'B1' by running git merge projB. The result is:

      ---projA -- a1 -- a2 -- A1    
     /                             
------------------------- master ---- A1' ---- B1'
     \                          
      ---projB -- b1 -- b2 -- B1

And that should be it, your project on master branch now has the form you wanted. I'll think a bit more about it to see if other things are possible.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top