首页 文章

有效地使用Git和Dropbox?

提问于
浏览
1075

如何有效地一起使用GitDropbox

19 回答

  • 8

    我认为Dropbox上的Git很棒 . 我一直都在使用它 . 我有多台计算机(两台在家,一台在工作),我使用Dropbox作为中央裸存储库 . 由于我不想在公共服务上托管它,并且我无法访问我总是可以访问的服务器,因此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帐户关联的 ~/Dropbox/git/project.git (或者与人共享此目录),您可以执行所有正常的Git操作,并且它们将自动同步到您的所有其他计算机 .

    我写了一篇博客文章,On Version Control,(old link死)关于我的推理以及我如何设置我的环境,这是基于我的Ruby on Rails开发经验,但它可以应用于任何事情,真的 .

  • 1

    正确的方法是使用git-remote-dropbox:https://github.com/anishathalye/git-remote-dropbox

    在Dropbox中创建自己的裸仓库会导致很多问题 . Anish(图书馆的创建者)explains it best

    这些问题的根本原因是Dropbox桌面客户端设计用于同步文件,而不是Git存储库 . 如果没有对Git存储库的特殊处理,它不会像Git那样保持相同的保证 . 远程存储库上的操作不再是原子操作,并发操作或不幸的同步时间可能导致存储库损坏 . 传统的Git远程控制器在服务器端运行代码以使其正常工作,但我们不能这样做 . 解决方案:可以正确解决此问题 . 即使有多个用户和并发操作,也可以将Git与Dropbox一起使用,并具有与传统Git遥控器相同的安全性和一致性保证!对于用户来说,它就像使用git-remote-dropbox一样简单,它是一个Git远程帮助器,充当Git和Dropbox之间透明的双向桥接器,并保持传统Git远程的所有保证 . 它甚至可以安全地与共享文件夹一起使用,因此它可以用于协作(与无限合作者一起使用无限制的私人回购!) . 使用远程帮助程序,可以将Dropbox用作Git远程并继续使用所有常规Git命令,如git clone,git pull和git push,一切都将按预期工作 .

  • 14

    我一直在推荐使用Mercurial,并敦促您保持谨慎,特别是如果任何机器不同的话 . Dropbox论坛充满了对自发出现的神秘文件名案例问题的抱怨 . Hg(我认为Git)在常规签到期间不会注意到或抱怨,当你试图将它用于真实时它会抱怨腐败的回购时你只能听到腐败 . 坏消息 . 希望我能更具体地解决这个问题及其解决方法;我还在努力从这个烂摊子中挖掘出来 .

  • 5

    这个答案是基于Mercurial经验,而不是Git,但是这种经验表明,如果在不同的时间从不同的机器更新同一个基于Dropbox的存储库,那么使用Dropbox就会要求损坏的存储库(Mac,Unix,Windows in my案件) .

    我没有可能出错的完整列表,但这里有一个特定的例子 . 每台机器都有自己的行尾字符概念,以及如何在文件名中处理大写/小写字符 . Dropbox和Git / Mercurial对此略有不同(我不记得确切的差异) . 如果Dropbox更新Git / Mercurial后面的存储库,那么presto就会破坏存储库 . 这种情况会立即发生并且不可见,所以在您尝试从中恢复之前,您甚至不知道您的存储库已损坏 .

    在从一个乱七八糟的事情中挖掘出这种方式之后,我一直在使用以下配方并取得了巨大的成功而没有任何问题的迹象 . 只需将您的存储库移出Dropbox即可 . 将Dropbox用于其他一切;文档,JAR files,你喜欢什么 . 并使用GitHub(Git)或Bitbucket(Mercurial)来管理存储库本身 . 两者都是免费的,因此这不会增加成本,现在每个工具都发挥其优势 .

    在Dropbox之上运行Git / Mercurial除了冒险之外什么都不会增加 . 不要这样做 .

  • 6

    关于使用Dropbox的小团队:

    如果每个开发人员在Dropbox上都有他们自己的可写裸存储库,这对其他开发人员来说就是 pull only ,那么这有助于代码共享而不会有腐败风险!

    然后,如果您想要一个集中的“主线”,您可以让一个开发人员通过他们自己的仓库管理所有推送 .

  • 0

    我不想把我的所有项目都放在一个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
    
  • 3

    我不认为使用Git和Dropbox是可行的方法......只要想想两者的特点:

    Git的方法:

    • 允许您拥有中央存储库

    • 允许您拥有自己的存储库并使用自己的更改

    • 允许您从中央存储库发送和接收更改

    • 允许多个人更改相同的文件并将它们合并或要求您合并它们,如果它不能这样做

    • 是否允许Web和桌面客户端访问中心知识库

    Dropbox的:

    • 将所有内容保存在中央存储库中

    • 允许您在服务器中拥有自己的文件版本

    • 强制您从中央存储库发送和接收更改

    • 如果多个人更改了相同的文件,则提交的第一个文件将被后续提交替换,并且不会发生合并,这很麻烦(绝对是最大的缺点)

    • 是否允许Web和桌面客户端访问中央存储库 .

    如果你担心分享你的一些文件,为什么不加密呢?然后你可以获得Dropbox到Git的最大优势,就是拥有公共和私人文件......

  • 0

    它现在是2015年,截至三天前,基于Dropbox API v2new tool已经创建,可以安全地在Dropbox上使用git . 它适用于API,而不是使用桌面客户端,并正确处理多个同时推送到托管在共享文件夹中的存储库 .

    配置完成后,就可以像任何其他git遥控器一样设置一个git遥控器 .

    git clone "dropbox::/path/to/repo"
    git remote add origin "dropbox::/path/to/repo"
    
  • 3

    我使用Mercurial(或Git)TrueCrypt Dropbox for encrypted remote backups .

    最酷的是,如果修改了一小部分代码,Dropbox不会同步整个TrueCrypt容器 . 同步时间大致与更改量成比例 . 即使它是加密的,TrueCrypt Dropbox的组合也可以很好地利用分组密码块级同步 .

    其次,单片加密容器不仅增加了安全性,还减少了存储库corruption的机会 .

    Caution: 但是在Dropbox运行时你必须非常小心没有安装容器 . 如果2个不同的客户端向容器签入不同的版本,则解决冲突也很麻烦 . 因此,它仅适用于使用它进行备份的单个人,而不适用于团队 .

    Build :

    • 创建一个Truecrypt容器(多个技嘉就好了)

    • 在Truecrypt首选项下,取消选中 preserve modification timestamp * .

    • 如上所述创建一个回购丹(https://stackoverflow.com/a/1961515/781695

    用法:

    • 退出Dropbox

    • 装载容器,推送更改,卸载

    • 运行dropbox

    附:取消选中 preserve modification timestamp 告诉Dropbox文件已被修改,并且应该同步'd. Note that mounting the container modifies the timestamp even if you don' t更改其中的任何文件 . 如果您不希望发生这种情况,只需将卷安装为 read-only

  • 5

    我喜欢Dan McNevin的回答!我 git push m在我的.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'
    
  • 95

    我们在 share folder 上使用此方法(在Dropbox中创建裸存储库) .

    一小组开发人员可以从该同步的存储库中获取并创建一个本地克隆 . 一旦工作单元完成,我们就会回到原点 .

    我遗漏的一件事是,一旦推送到原点,就可以通过变更集信息发送电子邮件 . 我们正在使用Google Wave手动跟踪更改 .

  • 4

    还有一个开源项目(跨平台[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和手册以获取完整的命令参考和教程 .

  • 86

    我将我的非Github回购存储在Dropbox上 . 我遇到的一个警告是在重新安装后同步 . Dropbox将首先下载最小的文件,然后再转移到较大的文件 . 如果你在晚上开始并在周末之后回来不是问题:-)

    我的主题 - http://forums.dropbox.com/topic.php?id=29984&replies=6

  • 16

    我喜欢Dan McNevin的最高投票回答 . 我最终做了很多次git命令的序列,并决定制作一个脚本 . 所以这里是:

    #!/bin/bash
    
    # Usage
    usage() {
        echo "Usage: ${0} -m [ master-branch-directory ] -r [ remote-branch-directory ] [ project-name ]"
        exit 1
    }
    
    # Defaults
    defaults() {
        masterdir="${HOME}/Dropbox/git"
        remotedir="${PWD}"
        gitignorefile="# OS generated files #\n\n.DS_Store\n.DS_Store?\n.Spotlight-V100\n.Trashes\nehthumbs.db\nThumbs.db"
    }
    
    # Check if no arguments
    if [ ${#} -eq 0 ] ; then
        echo "Error: No arguments specified"
        usage
    fi
    
    #Set defaults
    defaults
    
    # Parse arguments
    while [ ${#} -ge 1 ]; do
        case "${1}" in
            '-h' | '--help' ) usage ;;
            '-m' )
                shift
                masterdir="${1}"
                ;;
            '-r' )
                shift
                remotedir="${1}"
                ;;
            * )
                projectname="${1##*/}"
                projectname="${projectname%.git}.git"
                ;;
        esac
        shift
    done
    
    # check if specified directories and project name exists
    if [ -z "${projectname}" ]; then
        echo "Error: Project name not specified"
        usage
    fi
    
    if [ ! -d "${remotedir}" ]; then
        echo "Error: Remote directory ${remotedir} does not exist"
        usage
    fi
    
    if [ ! -d "${masterdir}" ]; then
        echo "Error: Master directory ${masterdir} does not exist"
        usage
    fi
    
    #absolute paths
    remotedir="`( cd \"${remotedir}\" && pwd )`"
    masterdir="`( cd \"${masterdir}\" && pwd )`"
    
    #Make master git repository
    cd "${masterdir}"
    git init --bare "${projectname}"
    
    #make local repository and push to master
    cd "${remotedir}"
    echo -e "${gitignorefile}" > .gitignore # default .gitignore file
    git init
    git add .
    git commit -m "first commit"
    git remote add origin "${masterdir}/${projectname}"
    git push -u origin master
    
    #done
    echo "----- Locations -----"
    echo "Remote branch location: ${remotedir}"
    echo "Master branch location: ${masterdir}"
    echo "Project Name: ${projectname}"
    

    该脚本只需要一个项目名称 . 它将在 ~/Dropbox/git/ 下以指定的名称生成一个git存储库,并将当前目录的全部内容推送到新创建的origin master分支 . 如果给出了多个项目名称,则将使用最右侧的项目名称参数 .

    (可选)-r命令参数指定将推送到原始主服务器的远程分支 . 也可以使用-m参数指定项目原点主文件的位置 . 默认的.gitignore文件也放在远程分支目录中 . 目录和.gitignore文件默认值在 . 中指定剧本 .

  • 15

    现在在2014年,我一直在使用Git和Dropbox大约一年半没有问题 . 但有些观点:

    • 我使用Dropbox的所有机器都在Windows上,不同版本(7到8)1 mac .

    • 我不与其他人共享存储库,所以我是唯一一个修改它的人 .

    • git push 推送到远程存储库,这样如果它被破坏,我可以轻松恢复它 .

    • 我必须在 C:\Users 中使用 mklink /D link target 创建别名,因为有些库指向绝对位置 .

  • 6

    我遇到了类似的问题,并为此创建了一个小脚本 . 我们的想法是尽可能简单地使用Dropbox和Git . 目前,我已经快速实现了Ruby代码,我很快就会添加更多代码 .

    该脚本可在 https://github.com/nuttylabs/box-git 访问 .

  • 2

    另一种方法:

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

    但是,由于最初的问题没有说明使用“Git和Dropbox有效地结合在一起”的真正含义,让我们采用另一种方法:“使用Dropbox仅同步工作树 . ”

    该方法有以下步骤:

    • 在项目目录中,一个创建一个空的 .git 目录(例如 mkdir -p myproject/.git

    • 取消同步Dropbox中的 .git 目录 . 如果使用Dropbox应用程序:转到首选项,同步和"choose folders to sync",其中 .git 目录需要取消标记 . 这将删除 .git 目录 .

    • 在项目目录中运行 git init

    如果 .git 已经存在,它也可以工作,然后只执行第2步 . 虽然Dropbox将保留网站中git文件的副本 .

    第2步将导致Dropbox不同步git系统结构,这是此方法的理想结果 .

    为什么会使用这种方法?

    • 尚未推送的更改将具有Dropbox备份,并且它们将在设备之间同步 .

    • 如果在设备之间同步时Dropbox会将某些内容搞砸, git statusgit diff 可以方便地解决问题 .

    • 它节省了Dropbox帐户的空间(整个历史记录不会存储在那里)

    • 它避免了@dubek和@Ates在@ Dan的答案评论中提出的问题,以及@clu在another answer中的担忧 .

    其他地方(github等)的存在将适用于这种方法 .

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

    • 一个潜在的问题是Dropbox(不必要地?)在检查不同的分支时同步可能很多的文件 .

    • 如果两个或多个Dropbox同步设备签出了不同的分支,则两个设备的未提交更改可能会丢失,

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

  • 16

    在不使用第三方集成工具的情况下,我可以稍微改善一下条件并使用DropBox和其他类似的 Cloud 盘服务,例如SpiderOak和Git .

    目标是避免在这些文件修改过程中进行同步,因为它可以上传部分状态,然后将其下载,完全破坏您的git状态 .

    为了避免这个问题,我做了:

    • 使用 git bundle create my_repo.git --all 将我的git索引捆绑在一个文件中 .

    • 设置文件监视的延迟,例如5分钟,而不是瞬时 . 这减少了DropBox在更改过程中同步部分状态的几率 . 在动态修改 Cloud 盘上的文件时(例如使用即时保存笔记应用程序),它也会有很大帮助 .

    这并不完美,因为不能保证它不会再次搞乱git状态,但它有帮助,目前我没有遇到任何问题 .

  • 1365

    对于我的2美分Dropbox只是为了个人使用,你可能会产生比你为这个用例设计的问题更多的问题 . 也就是说,在没有任何第三方插件或工具的情况下在Dropbox上转储存储库的一种非常安全的方法是使用bundle . 我在 .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
    

相关问题