0

I got 2 branches

a -- b -- c -- d -- e -- f -- g -- h     <-- master

a -- b -- c                              <-- Branch1
            

i need to apply the commits e, f and g onto Branch1

Tried with:

git rebase --onto gSha1 eSha1 hSha1 after checkout on Branch1 and it didn't worked (as said here)

tried with git cherry-pick eSha1^..gSha1 but it dont worked too (As mentioned here)

  • Can you clarify real quick... your chart suggests that at some point Branch1 was merged into master. Is that the case? Or is it the case that your Branch1 is just behind master? Do `a`, `b`, `c` and `d` have identical commit hashes? In that case your chart should not show the merge line from `d` to `d`. – JDB Dec 10 '20 at 20:05
  • branch1 is just behind master. They do have identical commit hashes. They're not merged, i misunderstood the diagram – William Brochensque junior Dec 10 '20 at 20:14
  • What does apply mean? What should happen to the original e f and g? What about h? – matt Dec 10 '20 at 21:09

2 Answers2

1

If you want a -- b -- c -- e -- f -- g

From

                           E---F---G  master
                          /            
                         D
                        /
               A---B---C  Branch1
git rebase --onto branch1 dSha1 gSha1

will give you

                         E'--F'--G'  HEAD
                        /              
                       | D---E---F---G  master
                       |/
               A---B---C  Branch1

Next set Branch1 to HEAD:

git branch -f Branch1 HEAD
                         D---E---F---G  master
                        /
               A---B---C---E'--F'--G' Branch1

Alternative

Set Branch1 to master and rebase Branch1 on commit C without D:

git co Branch1
git reset --hard master
git rebase --onto cSha1 dSha1 Branch1

If you want a -- b -- c -- d -- e -- f -- g (First question asked)

switch to Branch1

git checkout Branch1

then set Branch1 to g

git reset --hard gSha1

and here you are you can push or continue

Ôrel
  • 7,044
  • 3
  • 27
  • 46
0

Checkout branch1 and then git cherry-pick e f g. Do not use a range; that squashes the commits into one.

matt
  • 515,959
  • 87
  • 875
  • 1,141