Git not allowing unrelated histories

112 Views Asked by At

In order to have a clean history I create an empty branch using this command:

git checkout --orphan t0

then I did the first commit:

git commit -m "First commit"

The t0 has all the code of development branch now and is identical (source code wise)

After finishing my work I tried pull request but I got error that unrelated histories cannot be used in pull request.

I tried to merge it in development branch by doing this:

git merge development --squash --allow-unrelated-histories

But I get this message:

Automatic merge went well; stopped before committing as requested
Squash commit -- not updating HEAD

Can anyone guide me how to fix the issue and get my code into development?

1

There are 1 best solutions below

4
On

Git did precisely what you told it too. The merge went well (it even says so in the output). It didn't commit the merge because that's how a squash merge works:

Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit

Source: https://git-scm.com/docs/git-merge

You just need to commit the staged files. To perform a normal merge just remove the --squash flag.

In your case I would not recommend a squash merge. A normal merge will produce a commit with two parents to reflect the fact you merged two histories together.