如何使用git进行文件同步?

发布于 2024-08-19 03:38:28 字数 818 浏览 4 评论 0原文

我需要分布式文件同步。首先,有什么建议吗?我的想法是 git 因为速度是一个问题。

我的 git 知识还很初级,所以这就是我所做的。

我下载了便携式git(我在PC上所以msysgit)。 我将一个副本放入 c:\root\git 并将一个副本放入 c:\root\git c:\client\git\

我创建了一个目录 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

这将创建一个内容目录但它是空的!提交给 root 的文件不存在。

另外,当我执行拉命令时,我

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

显然错过了一个概念。这是怎么回事?

I have a need for distributed file synchronization. So first of all, any suggestions? My idea is git since speed is an issue.

My git knowledge is pretty rudimentary though so here's what I did.

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\

I created a directory c:\temp\root\content and created some files in it

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.

Also when I do a pull command I get

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?

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

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

发布评论

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

评论(5

寂寞笑我太脆弱 2024-08-26 03:38:28

查看 http://sparkleshare.org/

Sparkleshare 为您提供与 Dropbox 类似的用户体验,不同之处在于它是底层同步引擎是 git。它不是最稳定的东西,但你可以观察它的日志输出,看看它会使用哪些 git 命令来实现无缝同步。一旦学习了这些,您就可以简单地制作自己的稳定同步脚本。我认为 Sparkleshare 的大部分问题都出在 GUI 上。

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.

弱骨蛰伏 2024-08-26 03:38:28

git-annex 可能是另一个值得考虑的工具。

git-annex could be another tool to consider.

一个人的夜不怕黑 2024-08-26 03:38:28

Git可以成为在开发和生产之间同步源代码的好工具,原因之一是:它可以轻松地在生产中进行“热修复”并将修复检查回树中。当然,您应该始终在开发或测试环境中重现错误并修复它,但有时您做不到。

使用 git add 代替 git add *

在提交之前使用 git status 以确保适当的文件已暂存以供提交。

Git can be 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.

Instead of git add *, use git add .

Use git status before committing to make sure that the appropriate files are staged for commit.

为你拒绝所有暧昧 2024-08-26 03:38:28

我只是想重现你的步骤。

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 .

我在 repo1 中创建的文件出现在 repo2 中。

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.

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.

迷路的信 2024-08-26 03:38:28

正如 davr 在评论中建议的那样,您可以尝试 Unison。通过 让所有主机与中央集线器,可以进行n路同步。 Unison 不保留历史记录,因此如果您愿意,您应该安排 rdiff-backup 运行每天在您的一台主机上(最好是拥有最大、最可靠硬盘驱动器的主机)。这两个工具都有 Windows 二进制文件。

我也考虑过使用Git进行文件同步,但是手动添加、提交、拉取和合并工作量太大(工具只有用了才有用)。在我的脑海中,我设计了一个小的 Python 或 Ruby 系统托盘进程来监视您的存储库的更改,在它脏时提醒您,在一段时间没有更改后提供自动提交选项,以及自动推/拉。解决合并冲突可以使用现有工具来完成。

有关更多详细信息,请查看我刚刚写的有关个人文件同步的这篇文章

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-backup to run every day on one of your hosts (preferably whichever one has the largest, most reliable hard drive). Both tools have Windows binaries.

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.

For more details check out this article I just wrote about personal file synchronization.

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