0

enter image description here

I want to copy x-y-z to master, so in result it would be a-b-c-d-x-y-z

I've found two solutions:

  1. Git merge, but my x-y-z become 1 merged commit, which isn't what I want.
  2. Git cherry-pick, but I need to do it for every commit in secondary branch. Cherry-pick x, then cherry-pick y and then z. Which is too complicated.

So, is it way to do some "copy" method to achieve result as on scheme before?

Sergey Senkov
  • 1,490
  • 1
  • 13
  • 23
  • 2
    You can cherry pick a range of commits.. => [How to cherry pick a range of commits and merge into another branch?](https://stackoverflow.com/questions/1994463/how-to-cherry-pick-a-range-of-commits-and-merge-into-another-branch) – caramba Feb 01 '21 at 13:02
  • This is called a rebase – evolutionxbox Feb 01 '21 at 13:35

2 Answers2

1

If you haven't pushed x-y-z branch to remote you can do git rebase master. This wouldn't "copy", but rather "move" x-y-z commits on top of d commit. You'd lose exact time and date of the commits as well as their sha hashes should change because what rebase effectively does is replays your commits on top of the d commit.

Eimantas
  • 48,927
  • 17
  • 132
  • 168
0

So, the correct answer is cherry-pick with range. First you need to remember commits SHA-code first. Checkout to you secondary branch and type git log -5. Then checkout master. And use cherry-pick with params latest commit with ^ to include it and earliest commit of range:

git cherry-pick (SHA-code of z)^..(SHA-code of x)

In case you have a conflict, solve it and type

git cherry-pick --continue

Sergey Senkov
  • 1,490
  • 1
  • 13
  • 23