如何将 git 存储库的 COPY(存档,而不是克隆)连接到其远程? [英] How do I connect a COPY (an archive, not a clone) of a git repository to its remote?

查看:22
本文介绍了如何将 git 存储库的 COPY(存档,而不是克隆)连接到其远程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将 git 存储库的 COPY(存档,而不是克隆)与其远程存储库连接并同步.

I'd like to know to connect and sync a COPY (an archive, not a clone) of a git repo with its remote repo.

背景:我有一个本地和远程存储库.我使用 git archive 压缩我的本地存储库,然后将其复制到服务器:

Background: I have a local and remote repository. I zip up my local repository using git archive and then copy it to a server:

$ git archive --format=tar HEAD | gzip > myarchive.tar.gz

问题:在服务器上解压缩存档后,如何再次连接服务器副本并将其与远程存储库同步?

Question: After unzipping the archive on the server, how do I connect and sync the server's copy with the remote repository again?

如果我这样做:

$ git init
$ git remote add origin git@github.com/myusername:reponame.git
$ git fetch origin

git status 仍然将所有内容报告为未跟踪.

git status still reports everything as being untracked.

应该我应该做什么,以便我的解压文件夹与远程存储库完全同步,以便我可以简单地将任何未来的提交拉到远程存储库?

What should I be doing so that my unzipped folder is perfectly in sync with the remote repo, and so I can simply pull any future commits to the remote repo?

非常感谢,提姆

推荐答案

不要做存档:做 git bundle:这会给你一个文件,除了你可以从中拉取一次复制在偏远的地方.

Don't do an archive: do a git bundle: that will give you one file, except you will be able to pull from it once copied in the remote location.

请参阅如何通过电子邮件向某人发送 git 存储库?"

该捆绑包也可以是增量的(另请参阅git bundle 和 .patch 之间的区别").
这意味着您不必复制完整 存储库,只需复制自上次备份以来丢失的提交即可.

That bundle can be incremental too (see also "Difference between git bundle and .patch").
Meaning you don't have to copy over the full repos, only the missing commits since the last backup.

我有一个脚本可以访问我所有的裸仓库并每周进行一次完整备份,每天进行增量备份(如果检测到新提交):sbin/save_bundles.

I have a scripts which goes to all my bare repos and make a full backup once a week, incremental backups every day (if new commits are detected): sbin/save_bundles.

正如 Nevik Rehnel 提到的 在评论中, git archive 只会保存一个修订,这会使远程仓库中的任何同步不完整(缺少中间提交).

As Nevik Rehnel mentions in the comments, git archive would only save one revision, which would make any synchronization in the remote repo incomplete (missing intermediate commits).

另一种方法是tar 全部 repo,但这包括太多(包括可能的私人敏感文件,或钩子脚本).git bundle 是 git 方式.

Another approach is to tar the all repo, but that includes too much (including possible private sensitive files, or hook scripts). git bundle is the git way.

这篇关于如何将 git 存储库的 COPY(存档,而不是克隆)连接到其远程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆