peterh
peterh

Reputation: 1

How to tell git that two commits are the same?

Currently I have two branches, name it A and B:

    B1-...many dirty checkouts...-B2
   /
--O-A1-A2-......................-A3

Currently, B2 and A3 are the same (git diff A B gives an empty output).

Now the problem is, that this state was reached by partial checkouts from A. I.e. many times a git checkout -- dir1 dir2... happened and not a git merge.

Simply merging B to A totally craps A, what is impossible.

I don't want to lose B's history.

Somehow I should tell git, that a git merge A on the branch B shouldn't do anything.

Of course I could simply replace B2 with A3, but in this case I would lose B's history.

Is it somehow possible?

Upvotes: 1

Views: 364

Answers (2)

Kaz
Kaz

Reputation: 58637

What might help here is a different strategy in git merge via the -s option, like ours:

   ours
       This resolves any number of heads, but the resulting tree of the
       merge is always that of the current branch head, effectively
       ignoring all changes from all other branches. It is meant to be
       used to supersede old development history of side branches. Note
       that this is different from the -Xours option to the recursive
       merge strategy.

It sounds like this might just basically take the given branch you are on as-is, and create a commit with the additional heads as additional parents; i.e. what it seems you are trying to do.

Upvotes: 2

peterh
peterh

Reputation: 1

I've found a solution:

  1. I checkout B with a git checkout B.

  2. I merge A into B with a git merge A. Now B is locally in a crap state.

  3. But now I do a directory checkout with git checkout remotes/origin/B -- .. This restores B into its desired state.

  4. Now pushing up B (git push --all) will update the merge arrows as needed.

Upvotes: -1

Related Questions