git 如何使用git进行文件同步?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2124227/
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
How to use git for file synchronization?
提问by George Mauer
I have a need for distributed file synchronization. So first of all, any suggestions? My idea is git since speed is an issue.
我需要分布式文件同步。首先,有什么建议吗?我的想法是 git 因为速度是一个问题。
My git knowledge is pretty rudimentary though so here's what I did.
我的 git 知识还很初级,所以这就是我所做的。
I downloaded the portable git (I'm on PC so msysgit). I placed a copy into c:\root\git and a copy into c:\root\git c:\client\git\
我下载了便携式 git(我在 PC 上,所以是 msysgit)。我将副本放入 c:\root\git 并将副本放入 c:\root\git c:\client\git\
I created a directory c:\temp\root\content and created some files in it
我创建了一个目录 c:\temp\root\content 并在其中创建了一些文件
c:\root\content>..\git\bin\git.exe init
c:\root\content>..\git\bin\git.exe add *
c:\root\content>..\git\bin\git.exe commit -f
c:\client>..\git\bin\git.exe clone file:///c:\root\content
This creates a content directory but it is empty! The files committed to root are not there.
这将创建一个内容目录,但它是空的!提交给 root 的文件不存在。
Also when I do a pull command I get
此外,当我执行 pull 命令时,我得到
C:\temp\client\content\content>c:\temp\client\git\bin\git.exe pull
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
Your configuration specifies to merge the ref 'master' from the remote, but no such ref was fetched
Clearly I'm missing a concept. What's going on?
显然我缺少一个概念。这是怎么回事?
回答by lee
Check into http://sparkleshare.org/
Sparkleshare gives you a user experience similar to Dropbox, except that it's underlying sync engine is git. It's not the most stable thing, but you can watch it's log output to see what git commands it's going to achieve seamless syncing. Once you learn those, you can simply make your own sync scripts that are stable. I think most of sparkleshare's problems are in the GUI.
Sparkleshare 为您提供类似于 Dropbox 的用户体验,不同之处在于它的底层同步引擎是 git。这不是最稳定的东西,但你可以观察它的日志输出,看看它会用什么 git 命令来实现无缝同步。一旦你学会了这些,你就可以简单地制作自己的稳定同步脚本。我认为 sparkleshare 的大部分问题都在 GUI 中。
回答by Wayne Conrad
Git canbe a good tool for synchronizing source between development and production, for one reason: It makes it easy to "hot fix" in production and check the fix back into the tree. Of course you should always reproduce the bug in a development or test environment and fix it there, but sometimes you can't.
Git可以成为在开发和生产之间同步源代码的好工具,原因有一个:它可以轻松地在生产中“热修复”并将修复检查回树中。当然,您应该始终在开发或测试环境中重现错误并在那里修复它,但有时您不能。
Instead of git add *
, use git add .
而不是git add *
,使用git add .
Use git status
before committing to make sure that the appropriate files are staged for commit.
git status
在提交之前使用以确保适当的文件被暂存以进行提交。
回答by hillu
I just tried to reproduce your steps.
我只是试图重现您的步骤。
git commit -f
didn't do anything with the 1.6.5.1 version I just installed. But it should give you a long error message.
git commit -f
我刚安装的 1.6.5.1 版本没有做任何事情。但它应该给你一个很长的错误信息。
mkdir repo1 repo2
cd repo1
git init
( create files )
git add *
git commit -m "initial commit"
cd ..\repo2
git clone ..\repo1 .
and the files I created in repo1
appear in repo2
.
我在其中创建的文件repo1
出现在repo2
.
回答by Eric Drechsel
As davr suggested in the comments, you might try Unison. By having all your hosts sync with a central hub, you can have n-way synchronization. Unison doesn't preserve history, so if you want that you should schedule rdiff-backupto run every day on one of your hosts (preferably whichever one has the largest, most reliable hard drive). Both tools have Windows binaries.
正如 davr 在评论中建议的那样,您可以尝试Unison。通过让所有主机与中央集线器同步,您可以进行 n 路同步。Unison 不保留历史记录,因此如果您希望将rdiff-backup安排为每天在一台主机上运行(最好是拥有最大、最可靠硬盘驱动器的主机)。这两个工具都有 Windows 二进制文件。
I've also considered using Git for file synchronization, but manually adding, committing, pulling and merging is too much work (a tool is only useful if you use it). In my head I've designed a little Python or Ruby system tray process to watch your repo for changes, nag you when it's dirty, have options for autocommit after a period of no changes, and also do auto push/pull. Resolving merge conflicts would be done using an existing tool.
我也考虑过使用 Git 进行文件同步,但是手动添加、提交、拉取和合并工作量太大(工具只有在您使用它时才有用)。在我的脑海中,我设计了一个小的 Python 或 Ruby 系统托盘进程来观察你的 repo 的变化,在它脏的时候唠叨你,在一段时间没有变化后有自动提交的选项,也做自动推/拉。将使用现有工具解决合并冲突。
For more details check out this articleI just wrote about personal file synchronization.
欲了解更多详情请查看这篇文章我刚写了一篇个人文件同步。