当一个是另一个的子目录时,如何合并两个Git存储库而又不丢失提交历史记录? [英] How do you merge two Git repositories when one is a subdirectory of the other without losing commit history?

查看:218
本文介绍了当一个是另一个的子目录时,如何合并两个Git存储库而又不丢失提交历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • /root:服务器代码在此处
  • /root/client:客户端代码存在于此(服务器目录中的子目录).
  • /root中的1个回购跟踪服务器代码会忽略整个客户端目录
  • 1个回购跟踪代码仅在/root/client内.

我正在尝试合并这两个存储库,同时将一个存储库保留为另一个存储库的子目录,同时合并两个存储库的历史提交(不丢失任何一个).

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).

我发现在Internet上解决了许多情况,其中两个存储库具有1)相同文件或2)最终将在同一文件夹级别上合并在一起,但是在合并两个存储库(如果有一个存储库)方面没有发现太多是另一个子目录中的子目录.

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!

推荐答案

此步骤将合并两个master分支:

This steps will merge both master branches:

  1. 将客户端项目文件夹移动到服务器文件夹外部的文件夹(例如,tmp_client)
  2. 在新的客户端项目文件夹(tmp_client)内创建一个名为client的新文件夹.
  3. 将所有内容从tmp_client移至新的client文件夹
  4. 添加并提交更改:

  1. Move the client project folder to a folder to outside the server folder (for example, tmp_client)
  2. Inside the new client project folder (tmp_client) create a new folder called client.
  3. Move all the content from the tmp_client to the new client folder
  4. Add and commit the changes:

git add -A .添加更改

git 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这将合并更改

将更改推送到服务器git存储库

Push changes to the server git repository

git push server master

PD:如果要确保服务器分支中的一切正常,则可以创建一个新分支,而不是将其推送到服务器的工作分支中,然后合并新分支.

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.

这篇关于当一个是另一个的子目录时,如何合并两个Git存储库而又不丢失提交历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆