Git和Dropbox可以一起使用吗?


当前回答

现在是2015年,就在三天前,一个基于Dropbox API v2的新工具已经被创建出来,可以安全地在Dropbox上使用git。它针对API工作,而不是使用桌面客户端,并正确地处理多个同时推送到共享文件夹中托管的存储库。

一旦配置,它允许设置一个完全像其他git远程一样的git远程。

git clone "dropbox::/path/to/repo"
git remote add origin "dropbox::/path/to/repo"

其他回答

在不使用第三方集成工具的情况下,我可以稍微改善一下条件,并使用DropBox和其他类似的云磁盘服务,如带Git的SpiderOak。

我们的目标是避免在这些文件修改的中间同步,因为它可以上传一个部分状态,然后下载回来,完全破坏你的git状态。

为了避免这个问题,我做了:

使用git Bundle create my_repo将我的git索引捆绑在一个文件中。git——所有。 为文件监控设置一个延迟,例如5分钟,而不是瞬间。这降低了DropBox在更改过程中同步部分状态的机会。它在动态修改云磁盘上的文件时也有很大帮助(比如即时保存笔记应用程序)。

它并不完美,因为不能保证它不会再次弄乱git状态,但它有帮助,目前我没有遇到任何问题。

这个答案是基于Mercurial的经验,而不是Git,但这个经验告诉我们,如果你在不同的时间从不同的机器(对我来说是Mac、Unix和Windows)更新相同的基于Dropbox的存储库,那么以这种方式使用Dropbox会导致存储库损坏。

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.

在用这种方法解决了一次混乱之后,我一直在使用下面的食谱,而且非常成功,没有任何问题的迹象。只需将存储库移出Dropbox。其他事情都用Dropbox;文档,JAR文件,任何你喜欢的东西。并使用GitHub (Git)或Bitbucket (Mercurial)来管理存储库本身。这两种工具都是免费的,所以不会增加成本,而且现在每种工具都发挥了自己的优势。

在Dropbox上运行Git/Mercurial除了风险什么都不会增加。不要这样做。

现在是2015年,就在三天前,一个基于Dropbox API v2的新工具已经被创建出来,可以安全地在Dropbox上使用git。它针对API工作,而不是使用桌面客户端,并正确地处理多个同时推送到共享文件夹中托管的存储库。

一旦配置,它允许设置一个完全像其他git远程一样的git远程。

git clone "dropbox::/path/to/repo"
git remote add origin "dropbox::/path/to/repo"

在我看来,Dropbox只适用于个人用途,因为你不想麻烦地获得一个中央回收主机。对于任何专业开发来说,你可能会制造更多的问题,而不是解决更多的问题,就像已经在帖子中多次提到的那样,Dropbox并不是为这个用例而设计的。也就是说,在没有任何第三方插件或工具的情况下,在Dropbox上转储存储库的一个非常安全的方法是使用捆绑包。我在我的.gitconfig中有以下别名以节省输入:

[alias]
        bundle-push = "!cd \"${GIT_PREFIX:-.}\" && if path=\"$(git config remote.\"$1\".url)\" && [ \"${path:0:1}\" = / ]; then git bundle create \"$path\" --all && git fetch \"$1\"; else echo \"Not a bundle remote\"; exit 1; fi #"
        bundle-fetch = "!cd \"${GIT_PREFIX:-.}\" && if path=\"$(git config remote.\"$1\".url)\" && [ \"${path:0:1}\" = / ]; then git bundle verify \"$path\" && git fetch \"$1\"; else echo \"Not a bundle remote\"; exit 1; fi #"
        bundle-new = "!cd \"${GIT_PREFIX:-.}\" && if [ -z \"${1:-}\" -o -z \"${2:-}\" ]; then echo \"Usage: git bundle-new <file> <remote name>\"; exit 1; elif [ -e \"$2\" ]; then echo \"File exist\"; exit 1; else git bundle create \"$2\" --all && git remote add -f \"$1\" \"$(realpath \"$2\")\"; fi #"

例子:

# Create bundle remote (in local repo)
$ git bundle-new dropbox ~/Dropbox/my-repo.bundle
# Fetch updates from dropbox
$ git bundle-fetch dropbox
# NOTE: writes over previous bundle. Thus, roughly equivalent to push --force --prune --all
$ git bundle-push

正确的方法是使用git-remote-dropbox: https://github.com/anishathalye/git-remote-dropbox

在Dropbox中创建自己的裸回购会导致很多问题。Anish(库的创造者)解释得很好:

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.