Git和Dropbox可以一起使用吗?


当前回答

正确的方法是使用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.

其他回答

正确的方法是使用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.

我使用Mercurial(或Git) + TrueCrypt + Dropbox进行加密远程备份。

最酷的是,如果你修改了一小部分代码,Dropbox不会同步整个TrueCrypt容器。同步时间大致与更改量成比例。即使它是加密的,TrueCrypt + Dropbox的组合也很好地利用了块密码+块级同步。

其次,单片加密容器不仅增加了安全性,还减少了存储库损坏的可能性。

警告:但是你必须非常小心,不要在Dropbox运行时挂载容器。如果两个不同的客户端将不同的版本签入到容器中,解决冲突也会很麻烦。因此,它只适用于个人备份,而不适用于团队。

设置:

创建一个Truecrypt容器(多个gb就可以了) 在Truecrypt首选项下,取消选中保留修改时间戳*。 创建一个由Dan上面提到的回购(https://stackoverflow.com/a/1961515/781695)

用法:

Dropbox辞职 挂载容器,推送更改,卸载 dropbox运行

附注:取消选中保留修改时间戳告诉dropbox文件已被修改,它应该同步。注意,即使不更改容器中的任何文件,装入容器也会修改时间戳。如果不希望发生这种情况,只需将卷挂载为只读

我认为Dropbox上的Git很棒。我一直在用它。我有多台电脑(两台在家里,一台在公司),我把Dropbox作为一个中央的存储库。因为我不想把它托管在公共服务上,而且我也没有可以通过SSH访问的服务器,Dropbox通过在后台同步来解决这个问题(非常快)。

设置是这样的:

~/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

从那里,你可以克隆~/Dropbox/git/项目。git目录(无论它是否属于你的Dropbox帐户或在多个帐户之间共享)并执行所有正常的git操作-它们将自动同步到你所有的其他机器。

我写了一篇博客文章“关于版本控制”,其中介绍了环境设置背后的原因。它基于我的Ruby on Rails开发经验,但实际上它可以应用于任何东西。

在我看来,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和Dropbox是正确的选择……想想两者的特点:

Git:

允许您拥有一个中央存储库 允许您使用自己的更改拥有自己的存储库 允许您从中央存储库发送和接收更改 允许多人更改相同的文件,他们合并他们或要求你合并他们,如果它不能这样做 web和桌面客户端是否允许访问中央存储库

Dropbox:

将所有内容保存在中央存储库中 允许您在服务器中拥有自己的文件版本 强制您从中央存储库发送和接收更改 如果多人更改相同的文件,第一个提交的文件将被稍后提交的文件所取代,并且不会发生合并,这很麻烦(这肯定是它最大的缺点) 具有web和桌面客户端以允许访问中央存储库。

如果你担心泄露你的文件,为什么不加密呢?然后你就可以得到Dropbox to Git的最大优势,那就是拥有公共和私人文件……