使用 fetch 而不是 Push 备份 git 存储库

发布于 2024-10-04 03:58:55 字数 320 浏览 0 评论 0原文

如果您的 git 版本太旧,无法支持 gitolite 服务器上的 git push --mirror ,是否可以通过首先 git clone --bare 新存储库来模拟该功能,然后然后在备份服务器上使用 git fetch refs/*:refs/* ?您也可以将 *:* 指定为 refspec 吗?由于 gitolite 服务器上的存储库是裸存储库,因此如果 fetch 命令无法获取仅在有工作目录时使用的对象,那并不重要。

我的恢复策略是希望在当前服务器崩溃时将备份服务器 $BACKUPDIR 的内容复制到新的 gitolite 服务器。在这种情况下,这也能按预期工作吗?

If your git version is too old to support git push --mirror from your gitolite server is it possible to simulate the feature by first git clone --bareing new repositories and then using git fetch refs/*:refs/* on the backup server? Can you specify *:* as a refspec too? Since the repositories on the gitolite server are bare repos it doesn't matter if the fetch command doesn't manage to fetch objects that are only used when you have a working directory.

My recovery strategy would be to hopefully just copy the content of the backup server's $BACKUPDIR to the new gitolite server if the current one blows up. Would that also work as expected in this scenario?

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

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

发布评论

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

评论(1

站稳脚跟 2024-10-11 03:58:55

如果不安装旧版本的 git 并检查解决方案是否真的在此版本中工作,这个问题有点难以回答。 (无论如何,我不知道您对哪个版本感兴趣。)也就是说,我会尝试给出一些关于尝试什么的提示,您可以自己检查它是否适合您。

  1. 当您确实想要模拟 git Push --mirror 时,我认为没有任何理由使用 git fetch 而不是 git Push .

  2. 可以使用*:*作为refspec(至少在最新版本的git中)。这与 : 不同,因为后者仅选择两个存储库中都存在的分支,而前者选择发送站点上的所有分支并将它们发送到接收站点,必要时在那里创建新分支(这适用于 fetchpush)。

  3. 单个命令中 git push --mirror $REMOTE 最接近的近似值可能是

    git push -f $REMOTE *:*
    

    与“真实事物”的区别在于它永远不会删除远程端的分支。您可以忽略这一点——无论如何,备份可能是相当合理的——或者您可以破解一些代码来手动删除它们。这是我的(非常糟糕的)尝试:

    git ls-remote $REMOTE refs/* | git ls-remote $REMOTE refs/* |切-f 2 >远程分支
    git 显示参考 |切-d“”-f 2>本地分支机构
    git push --delete $(join -v 1 远程分支 本地分支)
    
    
    

    我确实认为这种尝试从根本上来说是有缺陷的——使用风险自负。无论如何,它可能不适用于旧版本的 git。 (令我惊讶的是 git show-ref 使用空格作为字段分隔符,而 git ls-remote 使用制表符来实现相同类型的输出。)

This question is a bit hard to answer without installing an old version of git and checking if the solutions really work in this version. (I wouldn't know which version you are interested in anyway.) That said, I will try and give some hints on what to try, and you can check for yourself if it works for you.

  1. I don't see any reason to use git fetch instead of git push when you actually want to simulate git push --mirror.

  2. You can use *:* as a refspec (at least in recent versions of git). This is different from :, as the latter only selects the branches which exist in both repositories, while the former selects all branches on the sending site and sends them to the receiving site, creating new branches there if necessary (this holds for both, fetch and push).

  3. The closest approximation of git push --mirror $REMOTE in a single command might be

    git push -f $REMOTE *:*
    

    A difference to the "real thing" is that it never deletes branches on the remote end. You can either ignore this -- it might be quite reasonable a backup anyway -- or you can hack some code to remove them manually. Here is my (really bad) attempt at this:

    git ls-remote $REMOTE refs/* | cut -f 2 > remote-branches
    git show-ref | cut -d " " -f 2 > local-branches
    git push --delete $(join -v 1 remote-branches local-branches)
    

    I do think this attempt is fundamentally flawed -- use at your own risk. And it might not work for old versions of git anyway. (I was surprised git show-ref uses spaces as field delimiter while git ls-remote uses tabs for the same kind of output.)

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