将 git 存储库移至另一台服务器

发布于 2024-08-09 22:30:15 字数 262 浏览 9 评论 0原文

我在开发服务器上有一个 git 克隆/存储库,但我现在正在转移到另一台服务器。我不想将所有本地分支和更改提交到主存储库,那么如何将旧服务器上的所有内容精确复制到新服务器?

我尝试了 oldserver:~$ scp -rp project newserver:~/project

但当尝试在 newserver 上执行任何操作时,我只是收到大量“typechange”错误。

有人提到了 x 模式,但是在服务器之间移动文件时如何保留它?

I have a git clone/repo on a development server, but I am now moving to another one. 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?

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

but then I just get loads and loads of "typechange" errors when trying to do anything on newserver.

Someone said something about x-modes, but how can I preserve that when moving files between servers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

余生一个溪 2024-08-16 22:30:15

如果您想要 git 解决方案,您可以尝试,

git clone --mirror <oldurl> <newurl>

尽管这仅适用于裸存储库。

如果这是一个非裸存储库,您也可以进行正常的克隆,然后进行如下操作:

git fetch origin
git branch -r | grep '^ *origin/[^ ]*

中间步骤当然可以通过 5000 种不同的方式完成,但这就是其中一种! (请注意,bash 中的管道之后不需要续行 - 它知道需要更多输入)

最后,如果您想直接复制,我建议使用 rsync 而不是 scp (可能使用 -avz 选项?)。 (这些类型更改错误到底是什么?)

| while read rb; do git branch --no-track ${rb#*/} $rb; done git remote rm origin

中间步骤当然可以通过 5000 种不同的方式完成,但这就是其中一种! (请注意,bash 中的管道之后不需要续行 - 它知道需要更多输入)

最后,如果您想直接复制,我建议使用 rsync 而不是 scp (可能使用 -avz 选项?)。 (这些类型更改错误到底是什么?)

If you want a git solution, you could try

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/[^ ]*

The middle step can of course be done in 5000 different ways, but that's one! (note that the continuation line \ isn't necessary after the pipe in bash - it knows it needs more input)

Finally, I'd suggest using rsync instead of scp (probably with -avz options?) if you want to directly copy. (What exactly are these typechange errors?)

| 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! (note that the continuation line \ isn't necessary after the pipe in bash - it knows it needs more input)

Finally, I'd suggest using rsync instead of scp (probably with -avz options?) if you want to directly copy. (What exactly are these typechange errors?)

半夏半凉 2024-08-16 22:30:15

我实际上已经做到了这一点,我所做的只是先将存储库 tar 起来并对其进行 scp 。我认为 scp -rp 也可以工作。

“类型更改”通常指的是诸如符号链接变成文件之类的事情,反之亦然。两台服务器运行相同的操作系统吗?

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.

"Typechange" would normally refer to things like a symlink becoming a file or vice-versa. Are the two servers running the same OS?

迷爱 2024-08-16 22:30:15

您可能还想尝试简单的愚蠢解决方案 - 不要担心类型更改是如何到达那里的,而是让 git 使用重置命令修复它们:

git reset --hard HEAD

只有当(1)问题都与签出有关时,这才有意义文件(而不是存储库结构本身)以及 (2) 您尚未对需要保留的 newserver 进行任何更改。

考虑到这些警告,当我发现自己遇到同样的问题时,它对我很有用,并且不需要您考虑 git 的内部结构或文件传输过程保留属性的情况。

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:

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文