DEV Community

Discussion on: Oops, I just pushed a git commit to the wrong branch. What now?

Collapse
 
nickraphael profile image
Nick Raphael

I completely agree. I think this is a better solution than my post. Let me run this past you...

First I can get the commit into the correct branch with:
git checkout Branch2
git cherry-pick 65c356c8c

I then undo the other commit with:
git checkout Branch1
git revert 65c356c8c

Is that your suggestion?

Collapse
 
erebos-manannan profile image
Erebos Manannán

Well your #1 priority should be to fix what you broke. Since revert does not remove the commit, you don't need to hurry with "saving it" or anything - first revert and push to fix what you broke, then you can go about cherry-picking it to where you needed the code in.