Revert the pushed code in wrong git branch using Cherry pick

git checkout wrong_branch
git revert commitsha1 # Code for wrong commit 
git revert commitsha2 # Code for wrong commit 
git checkout right_branch
git cherry-pick commitsha1 # Code for wrong commit 
git cherry-pick commitsha2 # Code for wrong commit 
 
If you have multiple commits and there are no commits pushed after your dirty commits, you can even use git reset to get that wrong branch to a state just before your commits and then follow that again using git cherry-pick to get your commits into the right branch.

git checkout wrong_branch
git reset commitsha3 #commit just before commitsha2, this will reset the whole branch to previous state
git checkout right_branch
git cherry-pick commitsha1
git cherry-pick commitsha2

Comments

Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Remove duplicates from a JavaScript Array

Sending Binary Data over the Network with Json