Reputation: 434
I am trying to fix a git repository that has gotten out of whack. Here's the issue.
What needs to be accomplished:
In the picture below, blue is master and red is the detached head.
Here's a second picture for reference.
Upvotes: 0
Views: 306
Reputation: 20417
So long no one else has cloned your repository, you should be able to do this.
Making a branch from the current master:
git branch <branch name> <commit hash for last commit on master before the merge>
Make master the detached head branch
git checkout master
git reset --hard <commit hash of last detached head commit before merge>
Now locally, you should be in the state you desire, but local master has different history to your remote master. You might be abe to just force push it to disregard the remote master
git push -f
However, services like gitlab and github will prevent you from doing this by default.
If anyone else has a local clone of the repository, this will cause them problems, making a fresh clone would be the easiest fix, if you're able to communicate with everyone affected.
Upvotes: 1