rsync .git 目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1398018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
rsync .git directory
提问by svrist
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. Could I rsync the complete directory structure between these hosts?
我的笔记本电脑上有一个存储库,唯一的方法是将它从 scp/rsync 移到远程主机,我可以从中再次下载它。我可以在这些主机之间同步完整的目录结构吗?
采纳答案by Ikke
Yes, that is possible. IIRC, git uses a relative approach. So it's safe to sync it with another computer.
是的,这是可能的。IIRC,git 使用相对方法。因此,将其与另一台计算机同步是安全的。
回答by Jakub Nar?bski
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 duringrsync
ing (same disclaimer as for usingrsync://
protocol).You can clone or fetch using deprecated
rsync
protocol (where repository URL / location looks like this: "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. It will (it did) disappear in Git 2.8.
Or you can create git bundle,
rsync
it orscp
it on other machine, and then clone or fetch from bundle.
您可以只
rsync
使用.git
存储库(甚至整个存储库和工作目录),前提是您在rsync
ing期间在存储库中没有任何活动(与使用rsync://
协议相同的免责声明)。您可以使用已弃用的
rsync
协议进行克隆或获取(其中存储库 URL/位置如下所示:“rsync://host.xz/path/to/repo.git/
”)。请注意,此协议已被弃用,因为如果存储库中有任何活动,您可能会获得损坏的克隆(或获取)。此外,正如我所听说的,自 2007 年以来,它在存在压缩参考的情况下无法正常工作,直到最近才有人注意到。它会(确实)在 Git 2.8 中消失。
或者您可以在其他机器上创建git bundle、
rsync
it 或scp
it ,然后从 bundle 中克隆或获取。
回答by Milan Babu?kov
You can rsync without any problems, but if you have some remotes declared with hostnames which are local to the machine (i.e. 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 本身来同步内容吗?
回答by VonC
Yes you can, but you should do so with a bare repository, as illustrated in this thread.
是的,您可以,但您应该使用裸存储库来执行此操作,如此线程中所示。
$ 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
).
(Merged by Junio C Hamano -- gitster
--in commit 9f03176, 17 Feb 2016)
请参阅Jeff King ( ) 的commit 0d0bac6(30 Jan 2016 )。(由Junio C Hamano合并-- --在提交 9f03176 中,2016 年 2 月 17 日)peff
gitster
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.
事实证明,
git clone
当源存储库长时间打包引用时,通过 rsync 传输的“ ”已被破坏,并且没有人注意到或抱怨它。
Commit 0d0bac6from Jeff King (peff
)has all the details.
来自Jeff King ( peff
) 的Commit 0d0bac6包含所有详细信息。
回答by Bombe
Yes, rsync
ing the .git
dir is possible and will result in a complete clone of the repository.
是的,可以rsync
对.git
dir 进行操作,并且会生成存储库的完整克隆。
回答by Cyrus Ivan
Using rsync to backup .git is possible, but with one catch ( at least to myself) It can not be updated. 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 备份 .git 是可能的,但有一个问题(至少对我自己而言)它无法更新。下次你再次尝试 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..
我知道,这是非常费力和愚蠢的.. 请让我知道有没有更好的方法来做到这一点..