在外部磁盘上备份整个 git 存储库的最佳方法是什么?

发布于 2024-10-06 19:57:20 字数 131 浏览 0 评论 0原文

所以我希望能够将可能有多个分支的 git 存储库备份到外部硬盘驱动器上,然后稍后能够将其复制回我的本地计算机并像往常一样使用它?我尝试简单地复制包含 .git 目录的工作目录文件夹,并且它有效。但是,我想知道这是否是最好的方法,或者以后是否有陷阱。

So I want to be able to back up a git repository that may have several branches onto an external hard drive and then be at a later time be able to copy it back onto my local machine and work with it as usual? I have tried simply copying the working directory folder containing the .git directory and it worked. However, I was wondering if this was the best way or if it had pitfalls later.

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

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

发布评论

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

评论(6

夏末 2024-10-13 19:57:20

使用常规文件系统复制命令复制整个工作副本效果很好。您还可以 zip/tar 备份。

如果您担心磁盘空间,您还可以查看“git bundle”,这可以生成更小的文件。

您还可以通过在外部磁盘上启动一个新的存储库(git克隆)然后每次拉取更改(git pull)来获得增量备份。在 git 这样的分布式系统中,备份和工作副本没有太大区别。

Copying the entire working copy using regular file system copy commands works fine. You can also zip/tar the backup.

If you are worried about disk space, you can also look at "git bundle", which could produce smaller files.

You can also get incremental backups by just starting a new repo on the external disk (git clone) and then pull the changes every time (git pull). There is not much difference between a backup and a working copy in a distributed system like git.

拥抱影子 2024-10-13 19:57:20

如果您的工作树中没有任何需要备份的更改,则可以使用 git clone --mirror 来创建一个裸克隆,其中所有引用(分支、标签,绝对是所有内容)都逐字复制。然后,您可以使用 git push --mirror 来逐步保持最新状态。这就是它的设计目的。

复制整个存储库(包括工作树)也可以,但增量执行有点麻烦,并且显然会占用更多空间。

If you don't have any changes to back up in your work tree, you can use git clone --mirror to create a bare clone with all refs (branches, tags, absolutely everything) copied verbatim. You can then use git push --mirror to keep it up to date incrementally. This is what it's designed for.

Copying the entire repo, including the work tree, works as well, but it's a bit of a pain to do incrementally, and obviously takes up more space.

攒一口袋星星 2024-10-13 19:57:20

除了将存储库克隆到外部磁盘之外,这是唯一的方法。但两种方法大致相同,只是复制克隆将保留任何特定于存储库的配置设置。

That's about the only way to do it, short of cloning the repository onto the external disk. But either approach is approximately equivalent, except that copying your clone will preserve any repo-specific config settings.

梦行七里 2024-10-13 19:57:20

总结一下,

  • 你可以复制该死的目录,当然它可以工作。
  • 你可以克隆。
  • 您可以git bundlegit archive

您也可以,

您可以将其转储到单个文件中,稍后可以从中导入。

$ git fast-export --all | (cd /empty/repository && git fast-import)

Summarizing,

  • You can just copy the damn directory, sure it works.
  • You can clone.
  • You can git bundle or git archive

You can also,

which you can dump into a single file that you can import later from.

$ git fast-export --all | (cd /empty/repository && git fast-import)
挽清梦 2024-10-13 19:57:20

这里没有陷阱,git 是一个完全分布式的 SCM。使用 .git 目录复制工作副本就足以进行备份。

There is no pitfall here, git is a fully distributed SCM. Copying a working copy with the .git directory is sufficient backup.

素年丶 2024-10-13 19:57:20

复制整个内容或使用同步工具都可以。该存储库是完全包含且可移植的。

Copying the whole thing or using a sync tool is fine. The repo is fully contained and portable.

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