【问题标题】:Create repository merging commits from other repository创建存储库合并来自其他存储库的提交
【发布时间】:2014-03-17 01:14:10
【问题描述】:

我有一台计算机(我们称它为 A),我一直在其中从事一个项目,并且那里有所有源代码。我创建了一个本地 Git 存储库,并且一直在进行多次提交。

现在我有了一台新计算机(我们称之为 B,我想将它设置为该存储库的服务器,这样我就可以在计算机 A 上工作,并且可以将代码推送到 B。
如果我从零开始,我会在 B 中创建 repo,然后从 A 中执行 git clone。问题是我已经在 A 中拥有代码,并且有很多我不能丢失的提交。我需要以某种方式将所有代码复制到 B,然后导入或合并我在 A 中的所有提交,然后我可以从 A 中 git clone。这有什么意义吗?

【问题讨论】:

  • 从 B 克隆存储库可以正常工作,您在 A 上的所有内容都将复制到那里。你到底在担心什么?

标签: git


【解决方案1】:

您可以初始化一个裸存储库,然后简单地推送您当前的历史记录:

git init --bare # On box B

然后:

git remote add origin <box b>
git push --mirror origin

man 页面解释了--mirror

   --mirror
       Instead of naming each ref to push, specifies that all refs under
       refs/ (which includes but is not limited to refs/heads/,
       refs/remotes/, and refs/tags/) be mirrored to the remote
       repository. Newly created local refs will be pushed to the remote
       end, locally updated refs will be force updated on the remote end,
       and deleted refs will be removed from the remote end. This is the
       default if the configuration option remote.<remote>.mirror is set.

另请参阅:Is "git push --mirror" sufficient for backing up my repository?

【讨论】:

    【解决方案2】:

    通过将项目克隆到计算机 B 上,您不会丢失任何提交。您可以在计算机 A 上工作,推送提交,然后将它们拉到计算机 B 上。也许我没有完全理解您的难题,但这似乎是最简单的解决方案。

    【讨论】:

      猜你喜欢
      • 2019-08-16
      • 2023-03-12
      • 1970-01-01
      • 2014-12-03
      • 2015-09-16
      • 1970-01-01
      • 2010-11-23
      • 2013-11-06
      • 2010-09-30
      相关资源
      最近更新 更多