如何将现有的Git存储库导入到另一个? [英] How to import existing Git repository into another?

查看:240
本文介绍了如何将现有的Git存储库导入到另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在名为 XXX 的文件夹中有一个Git存储库,并且我有第二个Git仓库,名为 YYY

我想将 XXX 存储库作为名为 ZZZ 的子目录导入 YYY 存储库并添加所有 XXX 的变更历史记录为 YYY



之前的文件夹结构:

  XXX 
| - .git
| - (项目文件)
YYY
| - .git
| - (项目文件)

之后的文件夹结构:

  YYY 
| - .git < - 现在包含来自XXX
| - ZZZ的变更记录< - 原本是XXX
| - (project文件)
| - (项目文件)

可以这样做吗?使用子模块?

解决方案

可能最简单的方法是将XXX内容拉入分支YYY,然后将它合并到master中:

在YYY中:

  git remote add other / path / to / XXX 
git fetch other
git checkout -b ZZZ other / master
mkdir ZZZ
git mv stuff ZZZ / stuff#必要时重复每个文件/目录
git commit -m把东西移到ZZZ
git checkout master
git merge ZZZ --allow-unrelated -storiesories#should add ZZZ / to master
git commit
git remote rm other
git branch -d ZZZ#在推送
之前摆脱额外的分支git push#如果你有一个远程的,也就是

其实我只是试了一下我的回购协议,它可以工作。不像Jörg的回答,它不会让你继续使用其他的回购,但我不认为你指定了。
$ b

注意:由于这是最初编写在2009年,git已添加子树合并在下面的答案中提到。我今天可能会使用这种方法,当然这个方法仍然有效。


I have a Git repository in a folder called XXX, and I have second Git repository called YYY.

I want to import the XXX repository into the YYY repository as a subdirectory named ZZZ and add all XXX's change history to YYY.

Folder structure before:

XXX
 |- .git
 |- (project files)
YYY
 |- .git
 |- (project files)

Folder structure after:

YYY
 |- .git  <-- This now contains the change history from XXX
 |-  ZZZ  <-- This was originally XXX
      |- (project files)
 |-  (project files)

Can this be done, or must I resort to using sub-modules?

解决方案

Probably the simplest way would be to pull the XXX stuff into a branch in YYY and then merge it into master:

In YYY:

git remote add other /path/to/XXX
git fetch other
git checkout -b ZZZ other/master
mkdir ZZZ
git mv stuff ZZZ/stuff                      # repeat as necessary for each file/dir
git commit -m "Moved stuff to ZZZ"
git checkout master                
git merge ZZZ --allow-unrelated-histories   # should add ZZZ/ to master
git commit
git remote rm other
git branch -d ZZZ                           # to get rid of the extra branch before pushing
git push                                    # if you have a remote, that is

I actually just tried this with a couple of my repos and it works. Unlike Jörg's answer it won't let you continue to use the other repo, but I don't think you specified that anyway.

Note: Since this was originally written in 2009, git has added the subtree merge mentioned in the answer below. I would probably use that method today, although of course this method does still work.

这篇关于如何将现有的Git存储库导入到另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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