Git和Dropbox可以一起使用吗?


当前回答

另一种方法:

到目前为止,所有的答案,包括最受欢迎的@Dan的答案,都提出了使用Dropbox来集中共享存储库的想法,而不是使用专注于git的服务,如github, bitbucket等。

但是,由于最初的问题并没有具体说明“有效地使用Git和Dropbox”的真正含义,让我们研究另一种方法: “使用Dropbox仅同步工作树。”

操作步骤如下:

在项目目录中,创建一个空的.git目录(例如mkdir -p myproject/.git) 取消同步Dropbox中的。git目录。如果使用Dropbox应用程序:进入“首选项”,“同步”,“选择要同步的文件夹”,其中。git目录需要去掉标记。这将删除.git目录。 在工程目录下运行git init

如果.git已经存在,它也可以工作,那么只执行步骤2。Dropbox会在网站上保留一份git文件的副本。

步骤2将导致Dropbox不同步git系统结构,这是这种方法的预期结果。

为什么要使用这种方法呢?

尚未发布的更改将在Dropbox上备份,并在不同设备之间同步。 如果Dropbox在设备之间同步时搞砸了,git状态和git diff将很方便地整理事情。 它节省了Dropbox帐户的空间(整个历史将不会存储在那里) 它避免了@dubek和@Ates在对@Dan的回答的评论中提出的担忧,以及@clu在另一个回答中提出的担忧。

其他地方的远程存在(github等)将很好地使用这种方法。

在不同的分支上工作会带来一些问题,需要注意:

一个潜在的问题是,当用户签出不同的分支时,Dropbox(不必要的?)可能会同步许多文件。 如果两个或多个Dropbox同步设备签出了不同的分支,对两个设备未提交的更改可能会丢失,

解决这些问题的一种方法是使用git工作树将分支签出保存在单独的目录中。

其他回答

还有一个开源项目(一个跨平台[Linux, Mac, Win]脚本的集合),它用少量(3-4)命令完成存储库管理的所有细节。

https://github.com/karalabe/gitbox/wiki

示例用法如下:

$ gitbox create myapp
Creating empty repository...
Initializing new repository...
Repository successfully created.

$ gitbox clone myapp
Cloning repository...
Repository successfully cloned.

之后正常的git使用:

$ echo “Some change” > somefile.txt
$ git add somefile.txt
$ git commit –m “Created some file”
$ git push

查看项目wiki和手册以获得完整的命令参考和教程。

我喜欢Dan McNevin的答案!我现在也在一起使用Git和Dropbox,我在我的.bash_profile中使用了几个别名,所以我的工作流看起来像这样:

~/project $ git init
~/project $ git add .
~/project $ gcam "first commit"
~/project $ git-dropbox

这些是我的别名:

alias gcam='git commit -a -m'
alias gpom='git push origin master'
alias gra='git remote add origin'
alias git-dropbox='TMPGP=~/Dropbox/git/$(pwd | awk -F/ '\''{print $NF}'\'').git;mkdir -p $TMPGP && (cd $TMPGP; git init --bare) && gra $TMPGP && gpom'

我认为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开发经验,但实际上它可以应用于任何东西。

在MacOS上,你也可以停止Dropbox,进行更改,然后重新启动Dropbox。 我正在使用以下组合,我很满意:

在这两个(本地git托管项目目录和位于Dropbox上的远程git存储库)中运行以下命令来禁用自动打包(这是Dropbox同步的主要问题)

git config --global gc.auto 0

然后不时地,压缩存储库dropbox禁用。例如,每当我发布应用程序的新版本时,我都会在bash-build-脚本中执行以下操作。

osascript -e "tell application \"Dropbox\" to quit"

# Compress local
git gc --prune=now; git repack -a -d

# Compress remote
REPOS_DIR_REMOTE=`git remote get-url --push origin`
cd "${REPOS_DIR_REMOTE}"
git gc --prune=now; git repack -a -d

osascript -e "tell application \"Dropbox\" to launch"
osascript -e "display notification with title \"Compress Done\""

I've been using Mercurial in the recommended manner and urge that you be cautious, especially if any of the machines differ. The Dropbox fora are full of complaints of mysterious filename case problems turning up spontaneously. Hg (and I presume Git) won't notice or complain during routine checkins and you'll only hear about the corruption when it complains of a corrupt repo when you try to use it for real. Bad news. Wish I could be more specific about the problem and its workarounds; I'm still trying to dig out from this mess myself.