Undo a Git merge that hasn’t been pushed yet

Explanation undo a Git merge

So here is the process where we can undo a Git merge that hasn’t been pushed yet

With git reflog check which commits is one prior to the merge (git reflog will be a better option than git log). Then you can reset it using:

git reset --hard commit_sha

We also have a different way that is as follow:

git reset --hard HEAD~1

 By this, we will get back 1 commit. 

 And always remember that any file that is modified or uncommitted/unstashed will get reset to its unmodified state. To keep them either stash changes away or see --merge the option is below.

git reset --hard ORIG_HEAD

 Also, note that if you do not want to reset your files unnecessarily. So you have to use --merge instead of using --hard .

git reset --merge ORIG_HEAD

–merge

This will help to fix the index. Also to update the file that is in the working tree. And the tree that is different between <commit> and HEAD. But it will keep the files that are different between the index and working tree. 

 

Also read, How to execute a program or call a system command?

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *