简体   繁体   English

rsync .git 目录

[英]rsync .git directory

This question probably is based on my lack of understanding of the role of .gits and git repositories in general but:这个问题可能是基于我对 .gits 和 git 存储库的作用缺乏了解,但是:

Can I rsync a dir with content that I created with git init between machines ?我可以在机器之间使用git init创建的内容同步目录吗?

I have a repository on my laptop, and the only way to get it away from there is scp/rsync to a remote host, from which I can download it again.我的笔记本电脑上有一个存储库,将其从那里移开的唯一方法是 scp/rsync 到远程主机,我可以从中再次下载它。 Could I rsync the complete directory structure between these hosts?我可以在这些主机之间同步完整的目录结构吗?

There are a few possibilities:有几种可能:

  • You can just rsync the .git repository (or even whole repository together with working directory), provided that you don't have any activity in repository during rsync ing (same disclaimer as for using rsync:// protocol).如果在 rsync 期间您在存储库中没有任何活动(与使用rsync rsync://协议相同的免责声明),您可以只rsync .git存储库(甚至整个存储库以及工作目录)。

  • You can clone or fetch using deprecated rsync protocol (where repository URL / location looks like this: " rsync://host.xz/path/to/repo.git/ ").您可以使用已弃用rsync协议进行克隆或获取(其中存储库 URL/位置如下所示:“ rsync://host.xz/path/to/repo.git/ ”)。 Note that this protocol is deprecated, because if there is any activity in repository, you can get corrupted clone (or fetch).请注意,此协议已弃用,因为如果存储库中有任何活动,您可能会得到损坏的克隆(或获取)。

    Also, as I have heard, it didn't work correctly in the presence of packed refs since 2007, and nobody noticed till recently.此外,正如我所听说的,自 2007 年以来,它在打包裁判的情况下无法正常工作,直到最近才有人注意到。 It will (it did) disappear in Git 2.8.它会(确实)在 Git 2.8 中消失。

  • Or you can create git bundle , rsync it or scp it on other machine, and then clone or fetch from bundle.或者您可以创建git bundle ,在其他机器上对其进行rsyncscp ,然后从 bundle 中克隆或获取。

Yes, that is possible.是的,这是可能的。 IIRC, git uses a relative approach. IIRC,git 使用相对的方法。 So it's safe to sync it with another computer.因此,与另一台计算机同步是安全的。

Yes you can, but you should do so with a bare repository, as illustrated in this 2012 article :是的,您可以,但您应该使用裸存储库来执行此操作,如2012 年的这篇文章所示:

$ git clone --bare ./projet projet.git
$ rsync -a --stats --delete ./projet.git/ votre.serveur:~/projets/projet.git/

Note: 6+ years later, git 2.8 (March 2016) will officially deprecate and fully remove the git rsync protocol !注意:6 年后,git 2.8(2016 年 3 月)将正式弃用并完全删除 git rsync 协议

See commit 0d0bac6 (30 Jan 2016) by Jeff King ( peff ) .请参阅Jeff King ( peff )提交 0d0bac6 (2016 年 1 月 30 日)。
(Merged by Junio C Hamano -- gitster -- in commit 9f03176 , 17 Feb 2016) (由Junio C Hamano -- gitster --提交 9f03176中合并,2016 年 2 月 17 日)

It turns out " git clone " over rsync transport has been broken when the source repository has packed references for a long time, and nobody noticed nor complained about it.事实证明,当源存储库长时间打包引用时,rsync 传输上的“ git clone ”已被​​破坏,没有人注意到或抱怨它。

Commit 0d0bac6 from Jeff King ( peff ) has all the details.来自Jeff King ( peff )Commit 0d0bac6包含所有详细信息。

You can rsync without any problems, but if you have some remotes declared with hostnames which are local to the machine (ie stored in /etc/hosts only) then those obviously won't work.您可以毫无问题地进行 rsync,但如果您声明了一些使用机器本地主机名的远程设备(即仅存储在 /etc/hosts 中),那么这些显然无法工作。

However, is there some reason why you don't use git itself to sync the content?但是,您不使用 git 本身来同步内容有什么原因吗?

是的, rsync.git目录是可能的,这将导致存储库的完整克隆。

Using rsync to backup .git is possible, but with one catch ( at least to myself) It can not be updated.使用 rsync 备份 .git 是可能的,但有一个问题(至少对我自己而言)它无法更新。 The next time you try to rsync it again, you got massive object rename.. and you can not delete those.. Been not familiar with rsync or linux system, I purge the .git backup before I rsync it.下次你再次尝试 rsync 时,你得到了大量的对象重命名.. 你不能删除那些.. 不熟悉 rsync 或 linux 系统,我在 rsync 之前清除了 .git 备份。

Which is:这是:

> chmod -R 777 /path/of/your/backup/.git
> rm -fr /path/of/your/backup/.git
> rsync /path/of/your/origin/.git /path/of/your/backup/.git

I know, this is very taxing and stupid.. Please let me know is there a better way to do this..我知道,这是非常费力和愚蠢的..请让我知道有没有更好的方法来做到这一点..

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

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