简体   繁体   English

将GIT仓库移至另一个仓库

[英]Move a GIT repo as a branch of another

How do I achieve the following? 我如何实现以下目标? I have a new repo New_Repo which is the current repo we all are working on. 我有一个新的仓库New_Repo,这是我们所有人都在努力的当前仓库。 I would like to create WhatINeed, but have repeatedly failed to do so. 我想创建WhatINeed,但是一再失败。

I understand that the commit ID will change and we are fine with this. 我了解提交ID将会更改,我们对此表示满意。

Old_Repo ........................... (Master, which is also v1)
            |......... (ModA) 

New_Repo.(Empty Master)
        |............. (v2)

WHatINeed.(Empty Master)
         |........................... (v1)
         |       |......... (ModA)
         |............. (v2)

I have been able to get to add the Old_repo/master onto the WhatINeed master. 我已经能够将Old_repo / master添加到WhatINeed主机上。 But its not a branch like I want it. 但是它不是我想要的分支。

I am already refering to Insert a commit before the root commit in Git? 我已经指的是在Git中的根提交之前插入提交? But this gives me a flat structure without the ModA branch. 但这给了我一个没有ModA分支的扁平结构。 Is there something wrong? 有什么不对?

Thank you in advance. 先感谢您。

If I understand correctly, you want to create a new branch (say, oldRepoBranch ) into WhatINeed repo that will have the same commit history of Old_Repo's master branch. 如果我理解正确,那么您想在oldRepoBranch WhatINeed库中创建一个新分支(例如oldRepoBranch ),该分支将具有与Old_Repo's master分支相同的提交历史记录。

Add a new remote (say, oldRepo ) with the url of Old_Repo into WhatINeed repo. 将具有oldRepo的URL的新远程服务器(例如oldRepoOld_RepoWhatINeed库中。

// WhatINeed repo
$ git remote add oldRepo <Old_Repo url> 
$ git fetch oldRepo

Create a new branch oldRepoBranch with the history of ldRepo/master . 使用ldRepo/master的历史记录创建一个新的分支oldRepoBranch

$ git checkout -b oldRepoBranch oldRepo/master
$ git log 
// oldRepoBranch commit history = Old_Repo/master commit history

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM