Replay the last N git commits on a different branch

自作多情 提交于 2019-11-29 19:43:35
  1. git checkout master
  2. git whatchanged testing
  3. git cherry-pick _________

?

Rebase should do it.

git rebase -p --onto master testing~10 testing

This will copy the last ten commits on testing to master and make that the new testing (the old testing will be an orphan). Then you can merge master to testing as a fast-forward.

git checkout master
git merge testing

As said in comments, the rebase-inspired answer is leaving the 'garbage' commits orphaned.

Just use simple tools:

git checkout master
git merge testing
git checkout testing
git reset --hard HEAD~10   # Go back 10 commits (*1)
git checkout master

(*1) You will only be "losing" commits from the testing branch, since you'll have those commits in master thanks to the merge.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!