DEV Community

How to move a commit to another branch in git

Kenny Grant on September 20, 2019

Here's a little git problem that happened to me today, which used to be quite scary when I was first learning git but is actually easy to remedy as...
Collapse
 
sodjanathan profile image
nat_souljah

What if I have already sent the changes to remote

Collapse
 
hnakao profile image
hnakao

git reset --hard HEAD~X // where X is the total of commit to move back

or

git reset --hard a1b2c3d4 // simply provide the hash of the commit you want to revert back to..

and

git push origin master --force // change "master" to the branch you want to revert.

Collapse
 
haritsinh profile image
Haritsinh Gohil

I will pray for you.

Collapse
 
katonadavid profile image
Dávid Katona

Thank you! Saved my a** :)

Collapse
 
harrybawsac profile image
Harry Bawsac

Thanks so much!

Collapse
 
ekimkael profile image
Ekim Kael

Guy! you just saved my life!
THANK YOU!!!!!

Collapse
 
hisham profile image
Hisham Mubarak

Thank you. Just what I wanted :)

Collapse
 
almaz_salyakhov_641e9d4c6 profile image
Almaz Salyakhov

git cherry-pick -x abcdef1
option -x add a message link to source commit — useful for history. It look (cherry picked from commit abcdef1)

Collapse
 
ajalasegun1 profile image
Segun Ajala

I signed up so i can tell you thank you

Collapse
 
cgritton profile image
Christopher Gritton

Thanks for the article! Helped me get my local commit back on track to the correct branch!