Git easy way revert pushed merge

37 views Asked by At

I pushed some changes to my branch (call it point A). I merged some changes from remote branch (call it point B). I pushed some new changes to my branch (call it point C). I realized than merge (B point) brought many mistakes. Is there an easy way to return to point A and merge it again?

1

There are 1 answers

0
Dillip Murali On

You can use git reflog show command to display all the previouly executed git commands

PS C:\Users\Dillip\OneDrive\Documents\VSCode\Test_cpp> git reflog show
8b6ac70 (HEAD -> test) HEAD@{0}: commit: replace.c
62ded08 HEAD@{1}: commit: Best_Time_to_Buy_And_Sell.c
1ec3f4a HEAD@{2}: reset: moving to HEAD
1ec3f4a HEAD@{3}: commit: k_freq_elements.c
6726350 HEAD@{4}: checkout: moving from dm to test
2d65f75 (mainline, dm) HEAD@{5}: reset: moving to HEAD~~
d4fec19 HEAD@{6}: checkout: moving from test to dm
6726350 HEAD@{7}: commit: two_sum.c 
3345c55 HEAD@{8}: commit: duplicate.c
2d65f75 (mainline, dm) HEAD@{9}: reset: moving to HEAD~
f4bc176 HEAD@{10}: commit (amend): Duplicate.c
1b8caf9 HEAD@{11}: cherry-pick: Duplicate.c

After finding which command (in your case the merge command) you want to revert you can use git reset HEAD@{5} command to return to point A