Reputation: 189
We have two branches A and B. For a while, all commits to B were being automatically merged into A by a backend process. At some point, we switched directions, now merging A commits into B. When the switch occurred, we did a git merge --strategy=ours
so that B would believe it had all content from A and only new content should actually be merged. Whether or not this was correct, it is done.
Now, we need to merge all content from A into B, but various git commands tell me there is no missing content. This makes sense, given the 'strategy' merge.
How should I approach this problem? Here are a few things I am exploring, where nothing is quite working as I hoped it would.
cherry-pick
. Now I have a new branch A' with a whole new set of SHAs, so I could merge it into B. One problem with this approach might be that many (30%) of the commits on A are merge commits. My first attempt using this idea, and cherry-picking only the first commit from A, did not produce what I expected.git apply
. The entire set of changes in A is very large, so I tried doing this by first generating a diff of only one logical set of changes (from tag 1 to tag 2 on A). When I try to apply it, I get lots of 'patch does not apply' messages.Is there any way to tell git to merge even though it has already been told the commit has been merged? I don't mind writing a script if a manual approach is the best. (We have 111 tags on branch A. At a minimum, the ones which occurred before the switch in merge direction need to be merged to B.)
Thanks for any advice.
Upvotes: 0
Views: 38
Reputation: 30277
If you want to do a merge that makes B
just like A
, you can do:
git checkout B
git merge --no-commit A
git restore --source A -- .
git merge --continue
Voila! Check with git diff A
and it should be empty.
If git complained because there is nothing to merge, that means that A
is already merged (it's tip) into B
.... So you could run a restore just like the one I used there and then a commit so that B
looks exactly like A
or you could create a new empty commit in A
and then follow the recipe I posted there from the beginning or (the hackish way) you could force creating a new commit out of thin air that has B
and A
as parents and A
's tree like this:
git commit-tree -p B -p A -m "a merge commit out of thin air" A^{tree}
That will print the ID of a commit that is just what you want.... Check its history and contents and if you like it, merge that commit ID into B
.
Upvotes: 0