不相关存储库的 Git 合并是否需要特定版本的 Git? [英] Does a Git merge of unrelated repos require a certain version of Git?

查看:62
本文介绍了不相关存储库的 Git 合并是否需要特定版本的 Git?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新组织我的代码目录并合并两个不相关的 Git 存储库.两个存储库都是本地的.

I'm trying to reorganize my code directory and merge two unrelated Git repos. Both repos are local.

我在这里发现了一个类似的问题:如何合并两个 Git 存储库?

I found a similar question here: How do you merge two Git repositories?

...但该解决方案对我不起作用.我在评论部分询问了这个问题,另一位用户建议我将我的问题作为一个单独的问题提出.

...but the solution didn't work for me. I asked in the comments sections about this and another user suggested I ask my question as a separate question.

我创建了一个测试/沙盒环境来测试解决这个 Git 合并问题.我的设置是:

I created a test/sandbox environment to test resolving this Git merge problem. My set up is:

/home/dir01/merge_repos  # this is the sandbox dir
|
/home/dir01/merge_repos/old_dir_01/old_repo # git init was done here; .git directory exists here

/home/dir01/merge_repos/old_dir_01/old_repo/source_file_01.py
/home/dir01/merge_repos/old_dir_01/old_repo/source_file_01.py
|
/home/dir01/merge_repos/new_repo  # git init was also done here.

我想将 old_repo 中的文件与 new_repo 中的 Git 存储库合并.

I want to merge the files in old_repo with the Git repo in new_repo.

根据原始问题中提供的解决方案,我执行了以下操作:

As per the solution offered in the original question, I did the following:

  1. 我在new_repo下创建了一个虚拟文件,然后对这个虚拟文件做了一个git add和git commit.

  1. I created a dummy file under new_repo, then did a git add and git commit of this dummy file.

在 new_repo/目录下,我发出 > git remote add old_repo/home/dir01/merge_repos/old_dir_01/old_repo

While in the new_repo/ directory, I issued > git remote add old_repo /home/dir01/merge_repos/old_dir_01/old_repo

git fetch old_repo --tags

git merge --allow-unrelated-history old_repo/master

在第 4 步,Git 抱怨 --allow-unrelated-history 是一个未知选项.

At Step 4, Git complains that --allow-unrelated-histories is an unknown option.

所以我尝试了一个没有 --allow-unrelated-history 选项的 git merge.这没有用;Git 抱怨 fatal: old_repo/master - 不是我们可以合并的东西.

So I tried a git merge without the --allow-unrelated-histories option. This didn't work; Git complained with fatal: old_repo/master - not something we can merge.

我的问题是,我可以使用早于 v2.9 的 Git 版本对两个不相关的 Git 存储库进行 Git 合并吗?

My question is, can I do a Git merge of two unrelated Git repos using a Git version that is older than v2.9?

我使用的是 Git v1.8.3.1.

I'm using Git v1.8.3.1.

推荐答案

为了跟进我最初的问题,不,您不需要特定版本的 Git 来执行 Git 合并.

To follow up on my original question, NO, you don't need a certain version of Git to do a Git merge.

对于 v2.9 或更高版本的 Git 版本,Git 提供了 --allow-unrelated-history 选项.所以你按照这里的回答来做:你如何合并两个 Git 存储库?

For Git versions that are v2.9 or later, Git provides the --allow-unrelated-histories option. So you do it as answered here: How do you merge two Git repositories?

cd path/to/project-b
git remote add project-a /path/to/project-a
git fetch project-a --tags
git merge --allow-unrelated-histories project-a/master 
git remote remove project-a

对于不支持 --allow-unrelated-history 选项的 Git 版本,您仍然可以进行 Git 合并,但有点不同.

For Git versions that do not support the --allow-unrelated-histories option, you can still do a Git merge but a bit differently.

cd path/to/project-b
git remote add project-a /path/to/project-a
git fetch project-a # Don't use the --tags option
git merge project-a/master # Don't use the --allow-unrelated-histories option
git remote remove project-a

感谢@paulsm4 的回答.

Thanks to @paulsm4 for the answer.

这篇关于不相关存储库的 Git 合并是否需要特定版本的 Git?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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