The following situation occured while cleaning-up on our Git server, and neither I, with my limited git knowledge, nor anyone of my collegues could find a solution, although im certain that im am not the first person to encounter this:
Suppose we have a large repository largeRepo. Inside this repository resides a folder largeRepo/path/in/large/to/module filled with files.
At some point in the past someone has made a hard-copy of only this folder ‘module‘, created a new repository module from it and continued working on this copy (~20 commits).
While he was doing this, work continued on largeRepo, including changes to the files included in largeRepo/path/to/module.
This clearly isn’t an ideal situation to be in, so it was decided that repository module should be closed and its changes merged back into the corresponding subfolder of repository largeRepo, ideally preserving the commit history of module.
First try was to add the small repository module as an remote to largeRepo and try to cherry-pick all commits from the remote, however the files from module ended up in the top-level of largeRepo and i did not find any modifier to cherry-pick into a specific folder.
Searching around on the web i found this thread How do you merge two git repositories, but the approach using subtree-merge presented there did not allow for the folder of the outer repository to already contain any files, e.g. performing a regular merge, as it threw ‘largeRepo/path/to/module/File.c overlaps with largeRepo/path/to/module/File.c. Cannot bind.’ errors. Commands where
git remote add -f module git@gitlab:module.git
git merge -s ours --allow-unrelated-histories --no-commit module/main
git read-tree --prefix=path/in/large/to/module/ -u module/main
-> Error: cannot bind
Experiments with ‘git diff > changes.patch’ and ‘patch -p1 changes.patch’ also lead to nowhere.
david_e is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.