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工作树将分支签出保存在单独的目录中。
其他回答
我使用Mercurial(或Git) + TrueCrypt + Dropbox进行加密远程备份。
最酷的是,如果你修改了一小部分代码,Dropbox不会同步整个TrueCrypt容器。同步时间大致与更改量成比例。即使它是加密的,TrueCrypt + Dropbox的组合也很好地利用了块密码+块级同步。
其次,单片加密容器不仅增加了安全性,还减少了存储库损坏的可能性。
警告:但是你必须非常小心,不要在Dropbox运行时挂载容器。如果两个不同的客户端将不同的版本签入到容器中,解决冲突也会很麻烦。因此,它只适用于个人备份,而不适用于团队。
设置:
创建一个Truecrypt容器(多个gb就可以了) 在Truecrypt首选项下,取消选中保留修改时间戳*。 创建一个由Dan上面提到的回购(https://stackoverflow.com/a/1961515/781695)
用法:
Dropbox辞职 挂载容器,推送更改,卸载 dropbox运行
附注:取消选中保留修改时间戳告诉dropbox文件已被修改,它应该同步。注意,即使不更改容器中的任何文件,装入容器也会修改时间戳。如果不希望发生这种情况,只需将卷挂载为只读
我不想把我所有的项目都放在一个Git存储库下,也不想为每个项目运行这些代码,所以我编写了一个Bash脚本来自动化这个过程。你可以在一个或多个目录上使用它——所以它可以为你完成这篇文章中的代码,也可以一次在多个项目上完成。
#!/bin/sh
# Script by Eli Delventhal
# Creates Git projects for file folders by making the origin Dropbox. You will need to install Dropbox for this to work.
# Not enough parameters, show help.
if [ $# -lt 1 ] ; then
cat<<HELP
projects_to_git.sh -- Takes a project folder and creates a Git repository for it on Dropbox
USAGE:
./projects_to_git.sh file1 file2 ..
EXAMPLES:
./projects_to_git.sh path/to/MyProjectDir
Creates a git project called MyProjectDir on Dropbox
./projects_to_git.sh path/to/workspace/*
Creates a git project on Dropbox for every folder contained within the workspace directory, where the project name matches the folder name
HELP
exit 0
fi
# We have enough parameters, so let's actually do this thing.
START_DIR=$(pwd)
# Make sure we have a connection to Dropbox
cd ~
if [ -s 'Dropbox' ] ; then
echo "Found Dropbox directory."
cd Dropbox
if [ -s 'git' ] ; then
echo " Dropbox Git directory found."
else
echo " Dropbox Git directory created."
mkdir git
fi
else
echo "You do not have a Dropbox folder at ~/Dropbox! Install Dropbox. Aborting..."
exit 0
fi
# Process all directories matching the passed parameters.
echo "Starting processing for all files..."
for PROJ in $*
do
if [ -d $PROJ ] ; then
PROJNAME=$(basename $PROJ)
echo " Processing $PROJNAME..."
# Enable Git with this project.
cd $PROJ
if [ -s '.git' ] ; then
echo " $PROJNAME is already a Git repository, ignoring..."
else
echo " Initializing Git for $PROJNAME..."
git init -q
git add .
git commit -m "Initial creation of project." -q
# Make the origin Dropbox.
cd ~/Dropbox/git
if [ -s $PROJNAME ] ; then
echo " Warning! $PROJNAME already exists in Git! Ignoring..."
else
echo " Putting $PROJNAME project on Dropbox..."
mkdir $PROJNAME
cd $PROJNAME
git init -q --bare
fi
# Link the project to the origin
echo " Copying local $PROJNAME to Dropbox..."
cd $PROJ
git remote add origin "~/Dropbox/git/$PROJNAME"
git push -q origin master
git branch --set-upstream master origin/master
fi
fi
done
echo "Done processing all files."
cd $START_DIR
在我看来,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
我们在共享文件夹上使用这种方法(在Dropbox中创建一个裸存储库)。
一小组开发人员可以从这个完全同步的存储库中提取数据,并创建一个本地克隆。一旦单位的功完成了,我们就回到原点。
我缺少的一件事是,在推送到原点时发送带有更改集信息的电子邮件的好方法。我们使用谷歌Wave来手动跟踪更改。
现在是2015年,就在三天前,一个基于Dropbox API v2的新工具已经被创建出来,可以安全地在Dropbox上使用git。它针对API工作,而不是使用桌面客户端,并正确地处理多个同时推送到共享文件夹中托管的存储库。
一旦配置,它允许设置一个完全像其他git远程一样的git远程。
git clone "dropbox::/path/to/repo"
git remote add origin "dropbox::/path/to/repo"