views:

361

answers:

2

I accidentally made 10 commits on branch "testing" when I meant to make them on branch "master". The other commits on the "testing" branch are garbage, so I don't want to merge it with "master". Instead, I just want to replay the last 10 commits on master.

+1  A: 
  1. git checkout master
  2. git whatchanged testing
  3. git cherry-pick _____

?

Ron
Just an fyi - cherry-pick will only do one commit at a time, so you'll have to cherry-picket testing~9 then testing~8 then ... testing. That's why I prefer the rebase approach that Talljoe suggested... of course the result is the same. In fact, if you do the rebase interactively, git will actually use cherry-pick under the hood.
Pat Notz
+11  A: 

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
Talljoe
Used Ron's answer before this was posted.
Horace Loeb
Perhaps worth noting that this leaves testing at the same point as master, leaving the 'garbage' commits orphaned. This may or may not be a good thing. Another possibility would be git checkout master; git reset --hard testing; git rebase --onto HEAD@{1} HEAD~10
Charles Bailey