问题
Current folder structure
- /root: server code exists here
- /root/client: client code exists here (a subdirectory within the server's directory).
Current git tracking
- 1 repo tracking Server code in /root that gitignores the entire client directory
- 1 repo tracking Client code only within /root/client.
The Problem
I am trying to merge these two repos while keeping one as the subdirectory of the other, combining the historical commits of both (not losing any).
Findings So Far
I have found a lot of situations resolved on the Internet in which two repos have either 1) the same files or 2) will eventually be merged together at the same folder level, but have not found much on merging two repos if one is a subdirectory within another.
Any help would be greatly appreciated. Thank you!
回答1:
This steps will merge both master
branches:
- Move the client project folder to a folder to outside the server folder (for example,
tmp_client
) - Inside the new client project folder (
tmp_client
) create a new folder calledclient
. - Move all the content from the
tmp_client
to the newclient
folder Add and commit the changes:
git add -A .
to add the changesgit commit -m "Move content to client folder"
Add a new remote branch for the server:
git remote add server git_server_repo_url
Pull changes from the server master branch
git pull server master
This will merge the changesPush changes to the server git repository
git push server master
PD: If you want to be sure all is ok in the server branch, you can create a new branch instead of pushing it to the working bramch of the server and then merge the new branch.
来源:https://stackoverflow.com/questions/44658948/how-do-you-merge-two-git-repositories-when-one-is-a-subdirectory-of-the-other-wi