Git和Dropbox可以一起使用吗?
当前回答
在不使用第三方集成工具的情况下,我可以稍微改善一下条件,并使用DropBox和其他类似的云磁盘服务,如带Git的SpiderOak。
我们的目标是避免在这些文件修改的中间同步,因为它可以上传一个部分状态,然后下载回来,完全破坏你的git状态。
为了避免这个问题,我做了:
使用git Bundle create my_repo将我的git索引捆绑在一个文件中。git——所有。 为文件监控设置一个延迟,例如5分钟,而不是瞬间。这降低了DropBox在更改过程中同步部分状态的机会。它在动态修改云磁盘上的文件时也有很大帮助(比如即时保存笔记应用程序)。
它并不完美,因为不能保证它不会再次弄乱git状态,但它有帮助,目前我没有遇到任何问题。
其他回答
我也遇到过类似的问题,并为此创建了一个小脚本。我们的想法是尽可能简单地使用Dropbox和Git。目前,我已经快速实现了Ruby代码,不久将添加更多代码。
该脚本可在https://github.com/nuttylabs/box-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上都有自己的可写裸存储库,这只对其他开发人员开放,那么这就有利于代码共享而没有损坏的风险!
然后,如果你想要一个集中的“主线”,你可以让一个开发人员从自己的回购中管理所有推送。
现在是2014年,我已经使用Git和Dropbox大约一年半了,没有任何问题。 以下是几点:
我所有使用Dropbox的电脑都是Windows操作系统,不同版本(7到8)+ 1个mac。 我不与其他人共享存储库,所以我是唯一一个修改它的人。 git push推送到一个远程存储库,这样如果它损坏了,我可以很容易地恢复它。 我必须在C:\Users中使用mklink /D链接目标创建别名,因为一些库指向绝对位置。
推荐文章
- 将文件的当前工作副本与另一个分支提交的副本区别对待
- 配置Git接受特定https远程的特定自签名服务器证书
- 如何将一个特定的提交从一个分支合并到Git中的另一个分支?
- 通过SSH配置Git登录一次
- 从pull请求中删除一个修改过的文件
- 如何使用Git恢复
- 如何提交没有变化和新的消息?
- 找到Git分支创建者
- 下载GitHub项目的最快方式
- git索引到底包含什么?
- 以树形输出git分支
- 如何点Go模块的依赖在Go。Mod到回购中的最新提交?
- 为什么调用git分支——unset-upstream来修复?
- Windows git“警告:LF将被CRLF取代”,这是警告尾巴向后吗?
- git中的哈希冲突