I need to copy one branch to another in git. I need to copy only the commits from fix branch to master, only the last three commits. How can I do that?
- x - x - x (master)
\
x - x (dev)
\
x - x - x (fix)
CodePudding user response:
You could say
git switch master
git cherry-pick dev..fix
Or you could do the same thing by saying
git switch fix
git switch -c temp
git rebase --onto master dev temp
git switch master
git reset --hard temp
git branch -D temp
Either way, now master has acquired three new commits which are copies of the three commits on fix after dev.
CodePudding user response:
You can create a new branch from master(say, hotfix-abcd), and cherry-pick the commits in fix.
Lets say you have these three commits in fix,
a1234 FixBob
a1235 FixAlice
a1232 FixTom
- Go to master,
git checkout master - Create a branch from the head,
git checkout -b 'hotfix-abcd' - Now you'll be in
hotfix-abcdbranch, cherry-pick the commitsgit cherry-pick a1234 a1235 a1232 - Create a Pull Request from
hotfix-abcdtomaster.
