Reputation: 20162
My situation looks like that:
I have two repositories with more or less the same code (let say repo A and B). I would like to pull repo B from repo A.
On repo A I execute following commands:
git remote add repoB path/to/repoB
git checkout -b branchB repoB/master
git merge branchB
Problem:
I get tons of both added
conflicts because both repositories consist of many identical files which were added in the first commit and left unchanged.
How to merge this repos without spending whole day on checking if "both added" files have different content or identical?
I would like to merge identical files automatically and leave only files which has different content for manual merge.
Upvotes: 2
Views: 1838
Reputation: 20162
Maybe someone can offer easier way to do this but the only option I found is:
git remote add repoB path/to/repoB git checkout -b branchB repoB/master
git rebase -i --root
git merge -Xours SHA_OF_BRANCHB_INITIAL_COMMIT
git rebase --continue
git merge branchB
Thanks to this solution all common files are merged in the first two commits so I can safely use -Xours
or -Xtheirs
in this merge
Upvotes: 3
Reputation: 60275
When merge has to work with a bad base, it gets inaccurate change hunks -- in this case, with the history showing no common ancestor at all, merge's autoresolve starts with every file showing as a single added change hunk.
One thing you could try is grafting the roots together:
echo $(git rev-list --max-parents=0 other) \
$(git rev-list --max-parents=0 HEAD) > .git/info/grafts
git merge
other
If that doesn't get good results, just abort the merge and yank the .git/info/grafts
file.
A general-purpose fallback is
git merge --no-commit --strategy ours
other
git diff ..other | git apply
git add --patch .
Upvotes: 1