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工作树将分支签出保存在单独的目录中。
其他回答
我也遇到过类似的问题,并为此创建了一个小脚本。我们的想法是尽可能简单地使用Dropbox和Git。目前,我已经快速实现了Ruby代码,不久将添加更多代码。
该脚本可在https://github.com/nuttylabs/box-git上访问。
我不想把我所有的项目都放在一个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
现在是2014年,我已经使用Git和Dropbox大约一年半了,没有任何问题。 以下是几点:
我所有使用Dropbox的电脑都是Windows操作系统,不同版本(7到8)+ 1个mac。 我不与其他人共享存储库,所以我是唯一一个修改它的人。 git push推送到一个远程存储库,这样如果它损坏了,我可以很容易地恢复它。 我必须在C:\Users中使用mklink /D链接目标创建别名,因为一些库指向绝对位置。
我不认为使用Git和Dropbox是正确的选择……想想两者的特点:
Git:
允许您拥有一个中央存储库 允许您使用自己的更改拥有自己的存储库 允许您从中央存储库发送和接收更改 允许多人更改相同的文件,他们合并他们或要求你合并他们,如果它不能这样做 web和桌面客户端是否允许访问中央存储库
Dropbox:
将所有内容保存在中央存储库中 允许您在服务器中拥有自己的文件版本 强制您从中央存储库发送和接收更改 如果多人更改相同的文件,第一个提交的文件将被稍后提交的文件所取代,并且不会发生合并,这很麻烦(这肯定是它最大的缺点) 具有web和桌面客户端以允许访问中央存储库。
如果你担心泄露你的文件,为什么不加密呢?然后你就可以得到Dropbox to Git的最大优势,那就是拥有公共和私人文件……
在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\""