My branching looks like this
M1 --- M2 --- M3 --- ............. --- M50 --- M51
\
\
P1 --- P2 --- P3 --- P4
\
\
C1 --- C2 --- C3
Here M is master commits P is parent branch commits C is child branch commits
I was developing a feature(F1) and created a branch(Parent) and had commits until P3. At this point I started working on new feature(F2), but since I needed P3 commit changes to work on new feature I created a branch(child) at P3. I got one review comment for feature F1 and had committed P4 in parent branch.
There was no conflict so I rebased the child branch to get something like this.
M1 --- M2 --- M3 --- ............. --- M50 --- M51
\
\
P1 --- P2 --- P3 --- P4
\
\
C1 --- C2 --- C3
Now my parent branch commits are squashed and merged with master at M52. Here I am confused on what happens with my child branch. I guess it is like this.
M1 --- M2 --- M3 --- ............. --- M50 --- M51 -- M52(contains squashed commits of P1-P4)
\
\
C1 --- C2 --- C3
If my guess is correct then what should be the right command to achieve something like this? Please let me know and next step if my guess is wrong too.
M1 --- M2 --- M3 --- ............. --- M50 --- M51 -- M52
\
\
C1 --- C2 --- C3
I believe it is again a rebase with onto, but I am not sure what it should be exactly? Plenty of teams work and merge their branches on master, so I don't want to take risk with wrong commands myself.
Thanks in advance.
CodePudding user response:
After the "squash & merge" of your parent branch, your history will look like this :
M1 --- M2 --- M3 --- ............. --- M50 --- M51 --- M52
\
\
P1 --- P2 --- P3 --- P4 # <- the 'Pxx' commits still exist
\
\
C1 --- C2 --- C3
The rebase command you are looking for is :
git rebase --onto M52 P4 child
After that, you will have to force push your child
branch to update it on the remote repo :
git push --force-with-lease origin child