开发者

How to use git for file synchronization?

开发者 https://www.devze.com 2022-12-17 03:15 出处:网络
I have a need for distributed file synchronization.So first of all, any suggestions?My idea is git 开发者_运维问答since speed is an issue.

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?


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.


git-annex could be another tool to consider.


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号