Search code examples
gitgit-mergegit-cherry-pick

Git copy from branch to master and save all commits


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?


Solution

  • 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