Git和Dropbox可以一起使用吗?
当前回答
我喜欢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'
其他回答
我不想把我所有的项目都放在一个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
这个答案是基于Mercurial的经验,而不是Git,但这个经验告诉我们,如果你在不同的时间从不同的机器(对我来说是Mac、Unix和Windows)更新相同的基于Dropbox的存储库,那么以这种方式使用Dropbox会导致存储库损坏。
I don't have a complete list of the things that can go wrong, but here's a specific example that bit me. Each machine has its own notion of line-ending characters and how upper/lower case characters are handled in file names. Dropbox and Git/Mercurial handle this slightly differently (I don't recall the exact differences). If Dropbox updates the repository behind Git/Mercurial's back, presto, broken repository. This happens immediately and invisibly, so you don't even know your repository is broken until you try to recover something from it.
在用这种方法解决了一次混乱之后,我一直在使用下面的食谱,而且非常成功,没有任何问题的迹象。只需将存储库移出Dropbox。其他事情都用Dropbox;文档,JAR文件,任何你喜欢的东西。并使用GitHub (Git)或Bitbucket (Mercurial)来管理存储库本身。这两种工具都是免费的,所以不会增加成本,而且现在每种工具都发挥了自己的优势。
在Dropbox上运行Git/Mercurial除了风险什么都不会增加。不要这样做。
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.
我使用Mercurial(或Git) + TrueCrypt + Dropbox进行加密远程备份。
最酷的是,如果你修改了一小部分代码,Dropbox不会同步整个TrueCrypt容器。同步时间大致与更改量成比例。即使它是加密的,TrueCrypt + Dropbox的组合也很好地利用了块密码+块级同步。
其次,单片加密容器不仅增加了安全性,还减少了存储库损坏的可能性。
警告:但是你必须非常小心,不要在Dropbox运行时挂载容器。如果两个不同的客户端将不同的版本签入到容器中,解决冲突也会很麻烦。因此,它只适用于个人备份,而不适用于团队。
设置:
创建一个Truecrypt容器(多个gb就可以了) 在Truecrypt首选项下,取消选中保留修改时间戳*。 创建一个由Dan上面提到的回购(https://stackoverflow.com/a/1961515/781695)
用法:
Dropbox辞职 挂载容器,推送更改,卸载 dropbox运行
附注:取消选中保留修改时间戳告诉dropbox文件已被修改,它应该同步。注意,即使不更改容器中的任何文件,装入容器也会修改时间戳。如果不希望发生这种情况,只需将卷挂载为只读
我也遇到过类似的问题,并为此创建了一个小脚本。我们的想法是尽可能简单地使用Dropbox和Git。目前,我已经快速实现了Ruby代码,不久将添加更多代码。
该脚本可在https://github.com/nuttylabs/box-git上访问。
推荐文章
- 将文件的当前工作副本与另一个分支提交的副本区别对待
- 配置Git接受特定https远程的特定自签名服务器证书
- 如何将一个特定的提交从一个分支合并到Git中的另一个分支?
- 通过SSH配置Git登录一次
- 从pull请求中删除一个修改过的文件
- 如何使用Git恢复
- 如何提交没有变化和新的消息?
- 找到Git分支创建者
- 下载GitHub项目的最快方式
- git索引到底包含什么?
- 以树形输出git分支
- 如何点Go模块的依赖在Go。Mod到回购中的最新提交?
- 为什么调用git分支——unset-upstream来修复?
- Windows git“警告:LF将被CRLF取代”,这是警告尾巴向后吗?
- git中的哈希冲突