knatten
knatten

Reputation: 5220

Git lost track of the fact that I was merging

I just completed a very difficult merge, but some time during the merge I did something that caused git to loose track of the fact that I was merging (I probably did git reset or something).

Now all the files I have locally are correctly merged, but I can't finish the merge since git doesn't know I'm merging. Any idea how to get out of this problem? The merge took a really long time, so I don't want to manually do it again. Basically I want to keep the local state exactly as it is, but just inform git that it should create a merge commit (from the current branch and a specific other branch) instead of a regular commit.

Upvotes: 3

Views: 77

Answers (1)

Enrico Campidoglio
Enrico Campidoglio

Reputation: 59923

Git looks for a reference called MERGE_HEAD1 to determine whether the next commit should be a merge commit. This reference should point to the tip of the branch to merge into the current one (i.e the target branch).

In your case, you can just create the MERGE_HEAD yourself by using the update-ref command:

git update-ref MERGE_HEAD $(git rev-parse <target-branch>)
git merge --continue

MERGE_HEAD is automatically deleted at the end of a merge operation, whether it was completed or aborted.


1 Which is nothing more than a text file in the .git directory, really.

Upvotes: 5

Related Questions