Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replay the last N git commits on a different branch

I accidentally made 10 commits on branch "testing" when I intended to commit 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.

like image 788
Tom Lehman Avatar asked Jun 10 '09 01:06

Tom Lehman


People also ask

What is the use of rebase?

Rebase is one of two Git utilities that specializes in integrating changes from one branch onto another. The other change integration utility is git merge . Merge is always a forward moving change record. Alternatively, rebase has powerful history rewriting features.


1 Answers

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 
like image 177
Talljoe Avatar answered Sep 20 '22 16:09

Talljoe