将 git repo 移动到第二台计算机?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5851966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:50:19  来源:igfitidea点击:

Moving a git repo to a second computer?

git

提问by mk.

I have a project with a simple local git repo, and I want to movethis project (folders etc.) to another computer and work from there from now on. I don't want to have anything left on the old machine (except of course my other git projects). I want it to be as if I have been working from the new machine all along.

我有一个带有简单本地 git 存储库的项目,我想将此项目(文件夹等)移动到另一台计算机并从现在开始工作。我不想在旧机器上留下任何东西(当然我的其他 git 项目除外)。我希望它就像我一直在新机器上工作一样。

Can I simply move all the files over to that computer, or will there be a problem with keys? Should I have the same key across two machines? If simply moving all the folders can't be done, what should I do? I want to avoid the hassle of setting up and learning to use a server, since this seems complicated and I don't want to alter my workflow.

我可以简单地将所有文件移到那台计算机上,还是密钥会出现问题?我应该在两台机器上使用相同的密钥吗?如果不能简单地移动所有文件夹,我该怎么办?我想避免设置和学习使用服务器的麻烦,因为这看起来很复杂,而且我不想改变我的工作流程。

回答by manojlds

For your case, the best way to do it is to copy over the folder (copy, scp, cp, robocopy - whichever) to the new computer and delete the old folder.

对于您的情况,最好的方法是将文件夹(复制、scp、cp、robocopy - 以任何一个)复制到新计算机并删除旧文件夹。

I completely disagree with @Pablo Santa Cruz that cloning is the paradigm for what you are doing. No it is not. You are moving a repo to a new computer.

我完全不同意@Pablo Santa Cruz 的观点,即克隆是您所做工作的范式。不它不是。您正在将存储库移至新计算机。

Why I don't like clone for this purpose:

为什么我不喜欢克隆用于这个目的:

  • It creates remote-tracking branches for each branch in the cloned repository. You are moving, and the old repo is defunct.
  • Any remote branches and other refs are completely ignored.
  • You don't get your hooks if you had any and you might forget that you had them!
  • You cannot get "lost" commits etc using git reflog or other means.Might not be a huge issue, especially if the repo acted as a server but something to be aware of.
  • 它为克隆的存储库中的每个分支创建远程跟踪分支。你在搬家,旧的回购已经不复存在了。
  • 任何远程分支和其他引用都将被完全忽略。
  • 如果你有钩子,你就不会得到你的钩子,你可能会忘记你有它们!
  • 您不能使用 git reflog 或其他方式获得“丢失”的提交等。可能不是一个大问题,特别是如果 repo 充当服务器但需要注意的事情。

If you search for ways to backup a git repo, git clone wouldn't be in the top answers. So it shouldn't be used for moving a repo! I also feel that just a git clonecannot be a proper answer because git clonehas the --mirroroption, which preservesthe repo, meaning that a git clonerepo is different from git clone --mirrorrepo (apart from being bare, the differences are mostly those I mentioned above). I would do a copy because I knowwhat I get with the copied repo - the samerepo!

如果您寻找备份 git 存储库的方法,则 git clone 不会出现在最佳答案中。所以它不应该用于移动回购!我也觉得 agit clone不能是一个正确的答案,因为git clone--mirror选项,它保留了 repo,这意味着git clonerepo 与git clone --mirrorrepo不同(除了裸露,差异主要是我上面提到的那些)。我会做一个副本,因为我知道我从复制的回购中得到了什么 -同一个回购!

When to consider git clone:

何时考虑 git clone:

  1. It is faster as git does some optimization while cloning
  2. You might have different git version on the new machine and a copy might make the repo unusable in the other version (not very common nowadays). But actually this can be another pro for copying, since this would inform you that that the new computer has a different git version.
  1. 它更快,因为 git 在克隆时进行了一些优化
  2. 您可能在新机器上有不同的 git 版本,并且副本可能会使 repo 在其他版本中无法使用(现在不太常见)。但实际上这可能是复制的另一个专业人士,因为这会通知您新计算机具有不同的 git 版本。

回答by ralphtheninja

Yes it's enough to copy the data to the other machine. Using git clone is almost the same thing, but it will setup the computer you are cloning from as the remote origin, which might not be what you want.

是的,将数据复制到另一台机器就足够了。使用 git clone 几乎是一回事,但它会将您从中克隆的计算机设置为远程源,这可能不是您想要的。

回答by Raymond Tan

While working on a project and you are forced to move to a new computer.

在处理项目时,您被迫搬到新计算机。

  1. Save files and copy files to new computer
  2. On new computer, install git and create ssh keys
  3. On each project folder run this

    git remote update

  1. 保存文件并将文件复制到新计算机
  2. 在新电脑上,安装 git 并创建 ssh 密钥
  3. 在每个项目文件夹上运行这个

    git远程更新

回答by KingCrunch

Because every clone is also a repo itself, just clone the first one on the your second computer.

因为每个克隆本身也是一个 repo,所以只需在第二台计算机上克隆第一个。

回答by Pablo Santa Cruz

Instead of copying, I would recommend you to clonethe repository. Cloning is the correct paradigm for what you are trying to accomplish. Cloned project will also contain all gitmetadata and information with it.

我会推荐您到clone存储库,而不是复制。克隆是您要完成的工作的正确范例。克隆的项目还将包含所有git元数据和信息。

On the destination machine:

在目标机器上:

$ git clone git://your-repo/proj proj

Instead of using git://you could also use ssh://or http://protocols to access the repository. Refer to gitmanual for further information.

除了使用,git://您还可以使用ssh://http://协议来访问存储库。git有关详细信息,请参阅手册。