How to make a merge of specific commits

6

I have a project called Proyect that has three ( 3 ) branches:

  • master ( M )
  • sdev ( S )
  • test ( T )
  • Which at the moment are like this:

    initial commit
    ↓   
    ↓   
    ↓      merge test into master
    ↓      checkout -b sdev master
    ↓      ↓ 
    ↓      ↓
    
    M------*------------------------------* # HEAD
    \     / \ 
     \   /   \
      \ /     \
       T-------\--------\--------------*    # commits behind master
                \        \
                 \        \
                  S-*--*---*---------*      # commits behind test behind master
    
                    ↑  ↑   ↑
                    ↑  ↑   ↑         
                    ↑  ↑   ↑
                    ↑  ↑   merge test into sdev           
                    ↑  ↑ 
                    ↑  ↑
                    ↑  commit 2 que quiero pushear directamente a master
                    ↑
                    ↑
                    commit 1 que quiero pushear directamente a master
    

    What I want to do and I do not know is to make a merge specific to the commit 1 and the commit 2 of the branch sdev directly to the branch master without affecting anything in the commits later of the branches sdev and test , I mean, I would like something like this:

    M------*------------------------------*-*--* # HEAD
    \     / \             ________________↑ ↑
     \   /   \           / _________________↑
      \ /     \         / /
       T-------\-------*-*------------------*    # commits behind master
                \     / / 
                 \   / /      
                  S-*--*---*--------------*      # commits behind test behind master
    
        
    asked by Jorius 01.09.2017 в 00:40
    source

    1 answer

    6

    I just had to use git cherry-pick

    First : I went to the branch sdev with a simple git checkout sdev

    Second : I searched for the unique identifiers SHA-1 of the commits of the sdev branch with a simple:
    git log --pretty=oneline , which threw me:

    <SHA-1> (origin/sdev) commit 1
    <SHA-1> (origin/sdev) commit 2
    

    Third : I went back to the branch master (which is where I wanted to make the merge )
    Fourth : Then I proceeded to perform the cherry-pick

    git cherry-pick <SHA-1>
    
      

    Everything OK, without any problems and / or conflicts

    git cherry-pick <SHA-1>
    
      

    Here I was presented with a conflict in several files
      I solved it manually and proceeded with

    git cherry-pick --continue
    

    The cherry-pick can be canceled by adding the option --abort

        
    answered by 01.09.2017 / 18:13
    source