Thilo
Thilo

Reputation: 262494

Specify merge parent in git

I have merged two of my branches (using the Eclipse merge tool).

When I commit, the commit has only one of the branches as parents (the original workspace HEAD). I'll dig into why that happens later, but I need to commit this properly right now (there was lot of work involved in the merge).

How can i amend the commit to include the reference to the other branch? The file contents are all good now, I just want to have the commit have two parents.

Upvotes: 2

Views: 427

Answers (1)

max
max

Reputation: 34407

First, if you have already committed, run git reset --soft HEAD^ to undo it.

Method 1

Create MERGE_HEAD file in GIT_DIR (usually /.git) which contains SHA-1 of the tip of the branch (you can get it using git show-ref) you are merging with (and an empty line, just to mimic git merge behavior). And commit as usual.

Method 2

Also, you can do it without messing with git internals, if you prefer:

  • save copy of your working directory (without .git directory) somewhere
  • do git reset --hard
  • do git merge branch_to_merge_with --no-commit
  • remove everything from working directory (except .git directory)
  • restore working directory content from saved copy
  • add changes & commit

P.S. it could happen if you've used git merge --squash option or MERGE_HEAD file was lost somehow.

Upvotes: 3

Related Questions