Git branch reinstall with grandparents

I am reading about git rebase

and reading through git-scm documentation.

I have definite onto

hesitation about using a function for git rebase to rebase a branch to its grandpa (just like the case in the link above).
Let's assume we have a branch / commit structure as shown below:

C1 <- C2 <- C5 <- C6 [master]
         <- C3 <- C4 <- C10 [server]
               <- C8 <- C9 [client]

      

Now I want to reinstall client

brnach on master

. I checked out the branch client

and ran the command git rebase --onto master server client

. The resulting structure I got (after merging and redirecting from presenter to client) is from this command:

C1 <- C2 <- C5 <- C6 <- C8' <- C9' [master, client]
         <- C3 <- C4 <- C10 [server]

      

My doubt is if my changes to branch client

depended on a C3 commit in the branch server

. The resulting code in the branch master

will of course not work in a scenario like rebase does. As far as I know, there shouldn't be an actual output (after merging and redirecting to the master client):

 C1 <- C2 <- C5 <- C6 <- C3' <- C8' <- C9' [master, client]
                             <- C4 <- C10 [server]

      

Can someone please let me know if my understanding / concern is wrong?

+3


source to share


2 answers


My doubt is if my changes to client branch depended on C3 commit to server branch. The resulting code in the master branch will of course not work in a scenario like rebase does

It is right. You have explicitly sliced ​​the C3 commit from your cumulative history. Why is this? Simple git rebase master client

. When you merge server

git, you won't try to apply the C3 changes again because they won't show up in diff (or alternate further changes to those lines).



edit: comoits are not "on" branches. History matters. The branch names are just lightweight ("throw" won't be such a bad word here) to help identify the commits you are interested in. Focus on the commtts themselves and their pedigree.

+1


source


If you start with

C1---C2---C5---C6  master
       \
        C3---C4---C10  server
          \
           C8---C9  client

      

and you expect the result to be

C1---C2---C5---C6---C3'---C8'---C9' master, client
                      \
                       C4---C10  server

      

Then misunderstanding: C3 'cannot be the ancestor of C4 . It can't be here.

When you do

git rebase --onto master server client

      

and as you put it, the changes in the client are dependent on changes from C3, you can allow the merge and you get

C1---C2---C5---C6  master
       \         \
        \         C8'---C9' client
         \
          C3---C4---C10  server

      

Now, after combining the master and client, and you are ready to reboot the server, two scenarios can occur:

1. If you saved changes from C8 that "depend" on C3 in a previous conflict, after resolving the current conflict, git will say



No change - did you forget to use 'git add'? If nothing is left to the stage, chances are that something else has already introduced the same change; you can skip this patch .

When you have solved this problem, run "git rebase -continue". If you'd rather skip this patch, run "git rebase -skip" instead. to check out your original branch and stop the reload, run "git rebase --abort".

Then you can do

git rebase --skip

      

and you get

C1---C2---C5---C6---C8'---C9'  master, client  
                             \         
                              C4'---C10' server

      

Please note that C3 does not exist as these changes were applied from C8.

2. If you have not saved changes from C8 that "depend" on C3 in a previous conflict, after you have resolved the current conflict and run

git rebase --continue

      

You'll get

C1---C2---C5---C6---C8'---C9'  master, client
                             \         
                              C3'---C4'---C10' server

      

This means that when you change <branch>

"depending" on <upstream>

that conflicts with a <newbase>

reload, git provides you with a merge resolution mechanism as a way to choose whether you want those changes now or later.

+2


source







All Articles