Using Git and Dropbox together effectively?
我如何有效地将Git和Dropbox一起使用?
I think that Git on Dropbox is great. I use it all of the time. I have multiple computers (two at home and one at work) that I use Dropbox as a central bare repository. Since I don't want to host it on a public service, and I don't have access to a server that I can always ssh to, Dropbox takes care of this by syncing (very quickly) in the background.
Setup is something like this:
~/project $ git init
~/project $ git add .
~/project $ git commit -m "first commit"
~/project $ cd ~/Dropbox/git
~/Dropbox/git $ git init --bare project.git
~/Dropbox/git $ cd ~/project
~/project $ git remote add origin ~/Dropbox/git/project.git
~/project $ git push -u origin master
From there, you can just clone ~/Dropbox/git/project.git
that you have associated with your Dropbox account (or have shared this directory with people), you can do all the normal Git operations and they will be synchronised to all your other machines automatically.
I wrote a blog post, On Version Control, (old link dead) on my reasoning and how I set up my environment, it's based on my Ruby on Rails development experience, but it can be applied to anything, really.
This answer is based on Mercurial experience, not Git, but this experience says using Dropbox this way is asking for corrupt repositories if there's even a chance that you'll be updating the same Dropbox-based repository from different machines at various times (Mac, Unix, Windows in my case).
I don't have a complete list of the things that can go wrong, but here's a specific example that bit me. Each machine has its own notion of line-ending characters and how upper/lower case characters are handled in file names. Dropbox and Git/Mercurial handle this slightly differently (I don't recall the exact differences). If Dropbox updates the repository behind Git/Mercurial's back, presto, broken repository. This happens immediately and invisibly, so you don't even know your repository is broken until you try to recover something from it.
After digging out from one mess doing things this way, I've been using the following recipe with great success and no sign of problems. Simply move your repository out of Dropbox. Use Dropbox for everything else; documentation, JAR files, anything you please. And use GitHub (Git) or Bitbucket (Mercurial) to manage the repository itself. Both are free so this adds nothing to the costs, and each tool now plays to its strengths.
Running Git/Mercurial on top of Dropbox adds nothing except risk. Don't do it.
The right way to do this is use git-remote-dropbox: https://github.com/anishathalye/git-remote-dropbox
Creating your own bare repo in Dropbox causes a lot of problems. Anish (the creator of the library) explains it best:
The root cause of these problems is that the Dropbox desktop client is designed for syncing files, not Git repositories. Without special handling for Git repositories, it doesn't maintain the same guarantees as Git. Operations on the remote repository are no longer atomic, and concurrent operations or unlucky timing with synchronization can result in a corrupted repository.
Traditional Git remotes run code on the server side to make this work properly, but we can't do that.
Solution: It is possible to solve this properly. It is possible to use Git with Dropbox and have the same safety and consistency guarantees as a traditional Git remote, even when there are multiple users and concurrent operations!
For a user, it's as simple as using git-remote-dropbox, a Git remote helper that acts as a transparent bidirectional bridge between Git and Dropbox and maintains all the guarantees of a traditional Git remote. It's even safe to use with shared folders, so it can be used for collaboration (yay unlimited private repos with unlimited collaborators!).
With the remote helper, it's possible to use Dropbox as a Git remote and continue using all the regular Git commands like git clone, git pull, and git push, and everything will just work as expected.
链接地址: http://www.djcxy.com/p/69072.html上一篇: 使用REST API的Dropbox差异/增量上传
下一篇: 将Git和Dropbox有效地结合使用?