简体   繁体   English

将2个Git Repo历史记录复制到新的父目录(我认为)

[英]Copy 2 Git Repo Histories To New Parent Directory (I Think)

I have .git repos in foo/bar and foo/baz . 我在foo/barfoo/baz.git foo/baz The projects began as separate projects but have since become identical. 这些项目开始时是单独的项目,但此后变得相同。

I now want to "copy" the two existing repos into the parent directory foo . 我现在想将两个现有存储库“复制”到父目录foo I've been reading up on subtree, filter, merging, moving, etc but I don't know what is the right thing to do. 我一直在阅读子树,过滤器,合并,移动等内容,但我不知道该怎么做。

I'm guessing I would create a new .git repo in the parent foo and "copy" the histories of both foo/bar and foo/baz into foo . 我猜我会在父foo创建一个新的.git库,并将foo/barfoo/baz的历史记录“复制”到foo Neither of the existing repos have branches. 现有的回购都没有分支。

If that's right, how do I go about doing it? 如果是的话,我该怎么做呢?

I don't want to delete the foo/bar and foo/baz histories. 我不想删除foo/barfoo/baz历史记录。 I just want to copy those histories into the new parent repo and continue committing to foo . 我只想将这些历史记录复制到新的父存储库中,然后继续提交给foo

Regardless or not whether there are conflicts, they can be resolved (quite clumsily though with no common ancestors, but nevertheless). 不管是否存在冲突,都可以解决(尽管没有共同的祖先,这很笨拙,但是)。

So, assuming the only branches in bar and baz are both called master , we do: 因此,假设barbaz中唯一的分支都称为master ,我们这样做:

$ cd /path/to/foo
$ git init
$ git remote add bar bar
$ git remote add baz baz
$ git fetch bar master:bar
$ git fetch baz master:baz

At this point you have a new foo repository with an empty branch master , a branch bar with the contents from the foo/bar repository and a branch baz with the contents from the foo/baz repository. 在这一点上,你有一个新foo与空分支仓库master ,分支bar从内容foo/bar库和分支baz从内容foo/baz库。

$ git merge bar
$ git merge baz

At this point, you may get merge conflicts if there are any files with the same name that had different contents. 此时,如果任何同名文件具有不同内容,则可能会发生合并冲突。 Example output: 输出示例:

Auto-merging somefile.txt
CONFLICT (add/add): Merge conflict in somefile.txt
Automatic merge failed; fix conflicts and then commit the result.

At this point somefile.txt will contain the contents of both versions. 此时,somefile.txt将包含两个版本的内容。 Resolve the conflicts as usual and do 像往常一样解决冲突并执行

$ git commit

to finish the merge. 完成合并。

As a result you now have a master branch with the history of both bar and baz joining up at merge commit you just created. 结果,您现在有了一个master分支,其中barbaz的历史在您刚创建的合并提交时结合在一起。 You also still have branches bar and baz and the remotes bar and baz . 您还仍然具有分支barbaz以及remotes barbaz You can get rid of them if you like. 如果愿意,可以摆脱它们。

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

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