Search code examples
gitgit-branchgit-mergegit-pullgit-fetch

Pull a commit into another branch exactly (without merging)


I have a structure similar to below:

C1 -- C2  --  C3
               \ -- C4

I want to pull C3 on back on top of C4. (NB: C3 & C3a hold the save files)

C1 -- C2  --  C3
               \ -- C4 -- C3a

If I try to merge or pull I am just told I am already up to date.

How can I force a 're-merge' so that I can get C3 back on top?


Solution

  • In your current branch, I don't think you can do that since C3 is already merged in the branch.

    You can try cherry-picking commits on a new branch though, which should give desired results:

    1. First, create new branch:

      git checkout -b new_branch <C1>
      
    2. Now cherry pick C4 on this new_branch:

      git cherry-pick C4
      
    3. Now cherry pick C# on the new_branch:

      git cherry-pick C3
      

    The above should give the desired results in the new_branch:

    C1 -- C2  --  C3
      \-- C4  -- C3