简体   繁体   English

将git repo移动到另一台服务器

[英]Moving a git repo to another server

I have a git clone/repo on a development server, but I am now moving to another one. 我在开发服务器上有一个git clone / repo,但我现在正转向另一个。 I don't want to commit all my local branches and changes to the main repository, so how can I make an exact copy of everything on oldserver to newserver? 我不想将所有本地分支和更改提交到主存储库,因此如何将oldserver上的所有内容完全复制到newserver?

I tried oldserver:~$ scp -rp project newserver:~/project 我试过oldserver:~$ scp -rp project newserver:~/project

but then I just get loads and loads of "typechange" errors when trying to do anything on newserver. 但是当我尝试在newserver上做任何事情时,我只是遇到了“typechange”错误的负载和负载。

Someone said something about x-modes, but how can I preserve that when moving files between servers? 有人说了一些关于x模式的东西,但是如何在服务器之间移动文件时保留它?

If you want a git solution, you could try 如果你想要一个git解决方案,你可以试试

git clone --mirror <oldurl> <newurl>

though this is only for bare repositories. 虽然这仅适用于裸存储库。

If this is a non-bare repo, you could also do the normal clone, followed by something like this: 如果这是一个非裸仓库,您也可以进行正常克隆,然后执行以下操作:

git fetch origin
git branch -r | grep '^ *origin/[^ ]*$' |
    while read rb; do git branch --no-track ${rb#*/} $rb; done
git remote rm origin

The middle step can of course be done in 5000 different ways, but that's one! 中间步骤当然可以用5000种不同的方式完成,但那就是一个! (note that the continuation line \\ isn't necessary after the pipe in bash - it knows it needs more input) (注意在bash中管道之后不需要连续行\\ - 它知道它需要更多输入)

Finally, I'd suggest using rsync instead of scp (probably with -avz options?) if you want to directly copy. 最后,如果你想直接复制,我建议使用rsync而不是scp(可能带有-avz选项?)。 (What exactly are these typechange errors?) (这些typechange错误究竟是什么?)

I've actually done this, and all I did was tar the repo up first and scp it over. 我实际上已经做到了这一点,而我所做的就是首先回购起来并将其翻过来。 I would think that scp -rp would work as well. 我认为scp -rp也会起作用。

"Typechange" would normally refer to things like a symlink becoming a file or vice-versa. “Typechange”通常指的是像符号链接变成文件的东西,反之亦然。 Are the two servers running the same OS? 两台服务器是否运行相同的操作系统?

You may also want to try the simple dumb solution -- don't worry about how the typechanges got there, but let git fix them with a reset command: 您可能还想尝试简单的愚蠢解决方案 - 不要担心typechanges如何到达那里,但让git使用reset命令修复它们:

git reset --hard HEAD

That only makes sense if (1) the problems all pertain to the checked-out files (and not the repository structure itself) and (2) you haven't made any changes on newserver which you need to preserve. 只有在(1)问题都与签出文件有关(而不是存储库结构本身)和(2)您没有对需要保留的newserver进行任何更改时才有意义。

Given those caveats, it worked for me when I found myself with the same problem, and it doesn't require you to think about git's internals or how well your file-transfer process is preserving attributes. 鉴于这些警告,当我发现自己遇到同样的问题时,它对我有用,并且它不需要你考虑git的内部或文件传输过程保存属性的程度。

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

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