JaedenRuiner
JaedenRuiner

Reputation: 359

Git Undo merge that removed uncommitted changes

Ok,

so the entire point of source control is to track changes so mess ups and deletions, or bad feature paths can be rectified - however we may need to do so.

Git is awesome for that. But recently something happened that blows my mind.

I have master, develop and Phase3 branches. Master and develop are remote branches where Phase3 was local. Develop recently was branched to a Release branch for testing. This branch was later merged back into master when our release went to production.
I am sitting here realizing that i need to merge master back into develop to maintain the commit history, and noted that Phase3 should probably also have the latest branch merged in.
this is where it all went south. I went to merge master into Phase3 and it destroyed ALL of my current changes.
It didn't ask for a merge request. It didn't even say "You might want to commit or stash your changes to current documents". It just overwrote them!!!!

I mean, I can't even check out alternate branches of a repository without Git warning me of possible data loss, but a merge can just overwrite these changes with nary a hint? WTF?

A) is there a way to tell the repository to UNDO this? (unlikely) B) is there a way to tell GIT to NEVER merge when there are active changes? Basically to get the same warning on a git merge as i get on a git checkout.

Thanks Jaeden "Sifo Dyas" al'Raec Ruiner

Upvotes: 1

Views: 1092

Answers (1)

ffledgling
ffledgling

Reputation: 12140

You need git reflog.

Look at the output of git reflog very carefully. Identify the state you were at before you ran the merge/rebase/whatever. Then do a

git reset --hard HEAD@{WHATEVER NUMBER FIND FROM THE REFLOG}

Upvotes: 1

Related Questions