在多台机器上使用Dropbox作为git工作目录 - 提交不完全同步 [英] Using Dropbox as git working directory across multiple machines - commits don't sync perfectly

查看:93
本文介绍了在多台机器上使用Dropbox作为git工作目录 - 提交不完全同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想强调一下,这个问题不是关于在Dropbox上托管我的中央回购,而且我对于使用git还相当陌生。没有任何其他涉及Dropbox和git的问题可以真正解答我的问题;他们都是关于托管你的仓库与Dropbox或者是否是一个好主意联合使用这两个,这两者都是我在这里问的。



我的问题如下:我有两台计算机,每台计算机都启动Windows和Ubuntu(一台笔记本电脑和一台桌面计算机)。我有位于Dropbox文件夹中的本地git存储库(从github repo克隆),以便在机器和操作系统之间同步。当我在一台机器/操作系统上进行提交时,它似乎没有将提交状态正确地同步到其他机器。



例如:



在我的Windows桌面上,我对foo.cpp进行了更改。然后我'git commit -a'和'git push',将我的更改推送到github托管的存储库。对文件的更改也会在我的Dropbox文件夹中同步,而且当我在学校登录我的Windows笔记本电脑时,所有内容都将毫无问题地下载下来。然而,当我输入'git status'时,它说:

 #在分支主上
#提交:
#(使用git add< file> ...更新将提交的内容)
#(使用git checkout - < file> ...放弃更改在工作目录中)

#modified:foo.cpp

没有更改添加到提交中(使用git add和/或git commit -a)

但我已经在另一台机器上提交了这些更改,表面上是同一个工作目录。试图从github服务器'git pull'给我的消息,一切都是'已经最新'。



我本来希望存储库状态是由Dropbox无缝同步。有人熟悉解决这种情况的方法吗?感谢! 不要使用Dropbox用于Git的并发操作。



最终一致性会导致您的悲伤



Dropbox为您提供事件一致性。使用它作为关键Git操作的后台存储是一个糟糕的想法&贸易;。如果您将它用作工作树而不是裸露的存储库,则会更糟糕。您当然可以做到这一点,但您需要了解这种方法的局限性。



Dropbox和 Spideroak Hive 很好,如果你想同时使用同步目录作为一个用户的工作树。在从其他系统访问文件和文件夹之前,请确保您的文件和文件夹已完全同步。只要你坚持单用户,单系统的工作流程,你不应该遇到麻烦,但你的里程可能会有所不同。

时间戳



如果您使用多台不同意时间的机器,则可能会遇到问题。如果您没有运行NTP,则一台机器的时钟可能在另一台机器的前面或后面。这可能会导致同步服务认为新文件实际上是较旧文件的情况(反之亦然)。简而言之,任何依赖时间戳的东西都可能容易出错。

如果您使用GNU make或其他依赖于它们的工具,时间戳的准确性尤其重要。如果您要使用Dropbox同步工作树,请确保您的计时在所有会触摸该树的系统中都是准确的。


First off, I'd like to emphasize that this question is NOT about hosting my central repo on Dropbox, and that I'm fairly new to using git. None of the other questions involving Dropbox and git that I could find really answer my question; they're all either about hosting your repository with Dropbox or whether or not it's a "good idea" to use the two in conjunction, neither of which is what I'm asking about here.

My question is as follows: I have two computers, each dual-booting Windows and Ubuntu (a laptop and a desktop). I've got my local git repository (cloned from a github repo) located in a Dropbox folder so that it is synced across machines and operating systems. When I make a commit on one machine/operating system, it doesn't seem to be syncing the commit status properly to the other machines.

e.g.:

On my Windows desktop, I make a change to foo.cpp. I then 'git commit -a' and 'git push', pushing my changes to the github hosted repository. The changes to the files are also synced across my Dropbox folder, and when I log into my Windows laptop at school, everything is downloaded without issue. However, when I type 'git status', it says:

# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   foo.cpp
#
no changes added to commit (use "git add" and/or "git commit -a")

But I've already committed these changes on my other machine in, ostensibly, the same working directory. An attempt to 'git pull' from the github servers gives me the message that everything is 'Already up to date.'

I would have hoped that the repository status would be seamlessly synchronized by Dropbox. Is anybody familiar with a way around this situation? Thanks!

解决方案

TL;DR

Don't use Dropbox for concurrent operations with Git.

Eventual Consistency Will Cause You Grief

Dropbox gives you eventual consistency. Using it as a backing store for critical Git operations is a Bad Idea™. It's even worse if you're using it as a working tree rather than as a bare repository. You can certainly do it, but you need to grok the limitations of this approach.

Dropbox and Spideroak Hive are fine if you want to use synced directories as a working tree for one user at a time. Just make sure that your files and folders are fully-synced before accessing them from another system. As long as you stick to a single-user, single-system workflow you shouldn't run into trouble, but your mileage may vary.

Timestamps

You may also run into problems if you're using multiple machines that don't agree on the time. If you aren't running NTP, one machine's clock could be ahead or behind of the other. This can lead to situations where the syncing service thinks a new file is in fact an older file (or vice-versa). In short, anything relying on timestamps may be error prone.

The accuracy of the timestamps are especially important if you are using GNU make or other tools that rely on them. If you're going to use Dropbox to synchronize a working tree, make sure your timekeeping is accurate across all systems that will touch that tree.

这篇关于在多台机器上使用Dropbox作为git工作目录 - 提交不完全同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆