in Technology by
How to Undo a Git merge that hasn't been pushed yet?

1 Answer

0 votes
by

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

git reset --hard commit_sha

There's also another way:

git reset --hard HEAD~1

It will get you back 1 commit.

Be aware that any modified and uncommitted/unstashed files will be reset to their unmodified state. To keep them either stash changes away or see --merge option below.


 in this direct case using:

git reset --hard ORIG_HEAD

might yield better results, as it should preserve your changes. ORIG_HEAD will point to a commit directly before merge has occurred, so you don't have to hunt for it yourself.


A further tip is to use the --merge switch instead of --hard since it doesn't reset files unnecessarily:

git reset --merge ORIG_HEAD

Related questions

0 votes
    In Git how do you revert a commit that has already been pushed and made public?...
asked Nov 2, 2020 in Technology by JackTerrance
0 votes
    Is there a way to revert a git commit that’s already been pushed and made public?...
asked Nov 4, 2020 in Technology by JackTerrance
0 votes
    What is the process for reverting a commit that has already been pushed and made public?...
asked Oct 4, 2020 in Technology by Editorial Staff
0 votes
    9. Cancel button (x on formula bar) can be used to undo a cell entry after it has been completed (a) True (b) ... ) Alt+P (d) Ctrl+P Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    Which value of Socket.readyState atribute of WebSocket indicates that the connection has not yet been established? A - 0 B - 1 C - 2 D - 3...
asked Dec 2, 2020 in Technology by JackTerrance
0 votes
    The _______________ policy, allows a transaction to commit even if it has modified some blocks that have ... Buffer Management in chapter Recovery System of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    How do I undo 'git add' before commit?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    Does anybody know how to easily undo a git rebase? The only way that comes to mind is to go at it manually: ... replayed. Not only one. Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    How to resolve merge conflicts in Git repository?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    What is a merge conflict in Git, and how can it be resolved?...
asked Oct 4, 2020 in Technology by Editorial Staff
0 votes
    I used git pull and had a merge conflict: unmerged: _widget.html.erb You are in the middle of a conflicted merge. ... can I do this? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    What is the difference between Git Merge and Git Rebase?...
asked Oct 4, 2020 in Technology by Editorial Staff
0 votes
    I have an old, out-of-sync project code in the master branch. Several files have been deleted, ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    How will you find out what all files have been changed in a particular Git commit?...
asked Nov 4, 2020 in Technology by JackTerrance
...