Programing

Git과 Dropbox를 효과적으로 함께 사용하십니까?

lottogame 2020. 9. 27. 12:40
반응형

Git과 Dropbox를 효과적으로 함께 사용하십니까?


GitDropbox 를 효과적으로 함께 사용하려면 어떻게해야 합니까?


Dropbox의 Git은 훌륭하다고 생각합니다. 나는 항상 그것을 사용합니다. Dropbox를 중앙 베어 저장소로 사용하는 여러 대의 컴퓨터 (집에 2 대, 직장에 1 대)가 있습니다. 공공 서비스에서 호스팅하고 싶지 않고 항상 ssh 할 수있는 서버에 액세스 할 수 없기 때문에 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/git/project.gitDropbox 계정과 연결 한 (또는이 디렉터리를 사람들과 공유 한) 복제 만하면 모든 일반 Git 작업을 수행 할 수 있으며 다른 모든 컴퓨터에 자동으로 동기화됩니다.

나는 내 추론과 내 환경을 설정하는 방법에 대한 블로그 게시물 On Version Control , ( old link dead )을 썼습니다. 이것은 Ruby on Rails 개발 경험을 기반으로 하지만 실제로는 모든 것에 적용될 수 있습니다.


이를 수행하는 올바른 방법은 git-remote-dropbox를 사용하는 것입니다 : https://github.com/anishathalye/git-remote-dropbox

Dropbox에서 나만의 베어 저장소를 만들면 많은 문제가 발생합니다. Anish (도서관 작성자) 가 가장 잘 설명합니다 .

이러한 문제의 근본 원인은 Dropbox 데스크톱 클라이언트가 Git 리포지토리가 아닌 파일 동기화 용으로 설계 되었기 때문입니다. Git 리포지토리에 대한 특별한 처리가 없으면 Git과 동일한 보장을 유지하지 않습니다. 원격 저장소에 대한 작업은 더 이상 원 자성이 아니며 동시 작업 또는 동기화와의 불운 한 타이밍으로 인해 저장소가 손상 될 수 있습니다.

기존의 Git 리모컨은 서버 측에서 코드를 실행하여 제대로 작동하도록 만들었지 만 우리는 그렇게 할 수 없습니다.

해결책 :이 문제를 제대로 해결할 수 있습니다. Dropbox와 함께 Git을 사용할 수 있으며 여러 사용자와 동시 작업이있는 경우에도 기존 Git 리모컨과 동일한 안전성과 일관성을 보장합니다!

사용자의 경우 Git과 Dropbox 간의 투명한 양방향 브리지 역할을하고 기존 Git 원격의 모든 보장을 유지하는 Git 원격 도우미 인 git-remote-dropbox를 사용하는 것만 큼 간단합니다. 공유 폴더와 함께 사용하는 것도 안전하므로 공동 작업에 사용할 수 있습니다 (예 : 무제한 공동 작업자가있는 무제한 개인 저장소!).

원격 도우미를 사용하면 Dropbox를 Git 원격으로 사용하고 git clone, git pull 및 git push와 같은 모든 일반 Git 명령을 계속 사용할 수 있으며 모든 것이 예상대로 작동합니다.


이 답변은 Git이 아닌 Mercurial 경험을 기반으로합니다 . 그러나이 경험에 따르면 Dropbox를 이런 방식으로 사용하면 여러 시간에 다른 컴퓨터 (Mac 제 경우에는 Unix, Windows).

나는 잘못 될 수있는 것들의 전체 목록을 가지고 있지 않지만, 여기에 나를 물린 구체적인 예가 있습니다. 각 컴퓨터에는 줄 끝 문자에 대한 고유 한 개념과 파일 이름에서 대 / 소문자가 처리되는 방식이 있습니다. Dropbox와 Git / Mercurial은 이것을 약간 다르게 처리합니다 (정확한 차이점은 기억 나지 않습니다). Dropbox가 Git / Mercurial 뒤에있는 저장소를 업데이트하면 손상된 저장소입니다. 이것은 즉각적이고 눈에 띄지 않게 발생하므로 저장소에서 무언가를 복구하려고 할 때까지 저장소가 손상되었음을 알지 못합니다.

이런 식으로 일을 한 번 엉망으로 파헤친 후 다음 레시피를 사용하여 큰 성공을 거두고 문제의 징후가 없습니다. 저장소를 Dropbox 밖으로 옮기기 만하면됩니다. 다른 모든 작업에는 Dropbox를 사용하세요. 문서, JAR 파일 , 원하는 모든 것. 그리고 GitHub (Git) 또는 Bitbucket (Mercurial)을 사용하여 저장소 자체를 관리합니다. 둘 다 무료이므로 비용이 추가되지 않으며 이제 각 도구가 강점을 발휘합니다.

Dropbox 위에서 Git / Mercurial을 실행하면 위험 외에는 아무것도 추가되지 않습니다. 하지마.


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

Git과 Dropbox를 사용하는 것이 좋은 방법이라고 생각하지 않습니다. 둘 다의 기능에 대해 생각해보십시오.

힘내 :

  • 중앙 저장소를 가질 수 있습니다.
  • 자신의 변경 사항으로 자신의 저장소를 가질 수 있습니다.
  • 중앙 저장소에서 변경 사항을 보내고받을 수 있습니다.
  • 여러 사람이 동일한 파일을 변경할 수 있도록 허용하고 이들이 병합하거나 할 수없는 경우 병합하도록 요청합니다.
  • 중앙 저장소에 대한 액세스를 허용하는 웹 및 데스크톱 클라이언트가 있습니다.

드롭 박스:

  • 모든 것을 중앙 저장소에 보관
  • 서버에 자신의 파일 버전을 가질 수 있습니다.
  • 중앙 저장소에서 변경 사항을 보내고 받도록합니다.
  • 여러 사람이 동일한 파일을 변경하면 첫 번째 커밋 된 파일이 이후 커밋으로 대체되고 병합이 발생하지 않아 문제가 발생합니다 (확실히 가장 큰 단점).
  • 중앙 저장소에 대한 액세스를 허용하는 웹 및 데스크톱 클라이언트가 있습니다.

일부 파일을 공유하는 것이 걱정된다면 암호화하지 않으시겠습니까? 그런 다음 Dropbox to Git의 가장 큰 이점, 즉 공개 및 비공개 파일을 가질 수 있습니다.


이제 2015 년이며 3 일 전 Dropbox에서 git을 안전하게 사용할 수 있도록 Dropbox API v2 기반 새로운 도구 가 생성되었습니다. 데스크톱 클라이언트를 사용하는 대신 API에 대해 작동하며 공유 폴더에 호스팅 된 저장소에 대한 여러 동시 푸시를 올바르게 처리합니다.

일단 구성되면 다른 git remote와 똑같이 git remote를 설정할 수 있습니다.

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

암호화 된 원격 백업을 위해 Mercurial (또는 Git) + TrueCrypt + Dropbox를 사용 합니다.

가장 멋진 점은 코드의 작은 부분을 수정하면 Dropbox가 전체 TrueCrypt 컨테이너를 동기화하지 않는다는 것입니다. 동기화 시간은 대략적으로 변경된 양에 비례합니다. 암호화되었지만 TrueCrypt + Dropbox의 조합은 블록 암호 + 블록 수준 동기화를 훌륭하게 사용합니다.

둘째, 모 놀리 식 암호화 컨테이너는 보안을 추가 할뿐만 아니라 저장소 손상 가능성도 줄여줍니다 .

주의 : 그러나 Dropbox가 실행되는 동안 컨테이너를 마운트하지 않도록주의해야합니다. 2 개의 다른 클라이언트가 컨테이너에 서로 다른 버전을 체크인하는 경우 충돌을 해결하는 것도 어려울 수 있습니다. 따라서 팀이 아닌 백업에 사용하는 한 사람에게만 실용적입니다.

설정:

  • Truecrypt 컨테이너 만들기 (여러 기가 바이트도 괜찮음)
  • Truecrypt 환경 설정에서 preserve modification timestamp*를 선택 취소하십시오 .
  • Dan ( https://stackoverflow.com/a/1961515/781695 )이 위에서 언급 한대로 저장소를 만듭니다.

용법:

  • Dropbox 종료
  • 컨테이너를 마운트하고, 변경 사항을 푸시하고, 마운트 해제
  • 보관 용 계정 실행

추신 : 체크 preserve modification timestamp를 해제하면 파일이 수정되었으며 동기화되어야 함을 드롭 박스 알립니다. 컨테이너를 마운트하면 파일을 변경하지 않아도 타임 스탬프가 수정됩니다. 그렇게하지 않으려면 볼륨을 다음과 같이 마운트하십시오.read-only


공유 폴더 에서이 방법 (Dropbox에 베어 저장소 생성)을 사용 합니다 .

소수의 개발자 그룹이 베어 동기화 된 저장소에서 가져와 로컬 복제본을 만들 수 있습니다. 작업 단위가 완료되면 원래 위치로 되돌립니다.

내가 놓친 한 가지는 원본으로 푸시가 발생하면 변경 세트 정보와 함께 전자 메일을 보내는 좋은 방법입니다. 변경 사항을 수동으로 추적하기 위해 Google Wave를 사용하고 있습니다.


저는 권장되는 방식으로 Mercurial을 사용해 왔으며 특히 기계가 다른 경우에는주의하시기 바랍니다. Dropbox 포럼은 저절로 발생하는 신비한 파일 이름 문제에 대한 불만으로 가득 차 있습니다. Hg (그리고 나는 Git라고 생각합니다)는 일상적인 체크인 중에 알아 차 리거나 불평하지 않을 것이며, 실제로 사용하려고 할 때 손상된 저장소에 대해 불평 할 때만 손상에 대해 듣게 될 것입니다. 나쁜 소식. 문제와 해결 방법에 대해 더 구체적으로 설명하고 싶습니다. 나는 아직도이 엉망진창에서 스스로를 파 내려고 노력하고있다.


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'

또한 몇 가지 명령 (3-4 개)으로 저장소 관리의 모든 핵심 세부 사항을 수행하는 오픈 소스 프로젝트 (크로스 플랫폼 [Linux, Mac, Win] 스크립트 모음)도 있습니다.

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.

그 후 정상적인 자식 사용 :

$ echo “Some change” > somefile.txt
$ git add somefile.txt
$ git commit –m “Created some file”
$ git push

전체 명령 참조 및 튜토리얼은 프로젝트 위키 및 매뉴얼을 확인하십시오.


Github가 아닌 저장소를 Dropbox에 저장합니다. 내가 만난 한 가지주의 사항은 재설치 후 동기화하는 것입니다. Dropbox는 큰 파일로 이동하기 전에 가장 작은 파일을 먼저 다운로드합니다. 밤에 시작해서 주말 후에 돌아 오면 문제가되지 않습니다. :-)

내 스레드 -http : //forums.dropbox.com/topic.php ? id=29984&replies=6


저는 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 저장소를 생성 하고 현재 디렉토리의 전체 내용을 새로 생성 된 원본 마스터 브랜치로 푸시합니다. 프로젝트 이름이 두 개 이상 제공되면 가장 오른쪽에있는 프로젝트 이름 인수가 사용됩니다.

Optionally, the -r command argument specifies the remote branch that will push to the origin master. The location of the project origin master can also be specified with the -m argument. A default .gitignore file is also placed in the remote branch directory. The directory and .gitignore file defaults are specified in the script.


Now in 2014, I have been using Git and Dropbox for about one year and a half without problem. Some points though:

  • All my machines using Dropbox are on Windows, different versions (7 to 8) + 1 mac.
  • I do not share the repository with someone else, so I am the only one to modify it.
  • git push pushes to a remote repository, so that if it ever gets corrupted, I can easily recover it.
  • I had to create aliases in C:\Users with mklink /D link target because some libraries were pointed to absolute locations.

For my 2 cents Dropbox only makes sence for personal use where you don't want to bother getting a central repo host. For any professional development you'll probably create more problems than you'll solve, as have been mentioned several times in the thread already, Dropbox isn't designed for this use case. That said, a perfectly safe method to dump repositories on Dropbox without any third-party plugins or tools is to use bundles. I have the following aliases in my .gitconfig to save typing:

[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 #"

Example:

# 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

I have faced a similar issue and have created a small script for the same. The idea is to use Dropbox with Git as simply as possible. Currently, I have quickly implemented Ruby code, and I will soon add more.

The script is accessible at https://github.com/nuttylabs/box-git.


Another approach:

All the answers so far, including @Dan answer which is the most popular, address the idea of using Dropbox to centralize a shared repository instead of using a service focused on git like github, bitbucket, etc.

But, as the original question does not specify what using "Git and Dropbox together effectively" really means, let's work on another approach: "Using Dropbox to sync only the worktree."

The how-to has these steps:

  1. inside the project directory, one creates an empty .git directory (e.g. mkdir -p myproject/.git)

  2. un-sync the .git directory in Dropbox. If using the Dropbox App: go to Preferences, Sync, and "choose folders to sync", where the .git directory needs to get unmarked. This will remove the .git directory.

  3. run git init in the project directory

It also works if the .git already exists, then only do the step 2. Dropbox will keep a copy of the git files in the website though.

Step 2 will cause Dropbox not to sync the git system structure, which is the desired outcome for this approach.

Why one would use this approach?

  • The not-yet-pushed changes will have a Dropbox backup, and they would be synced across devices.

  • In case Dropbox screws something up when syncing between devices, git status and git diff will be handy to sort things out.

  • It saves space in the Dropbox account (the whole history will not be stored there)

  • It avoids the concerns raised by @dubek and @Ates in the comments on @Dan's answer, and the concerns by @clu in another answer.

The existence of a remote somewhere else (github, etc.) will work fine with this approach.

Working on different branches brings some issues, that need to be taken care of:

  • One potential problem is having Dropbox (unnecessarily?) syncing potentially many files when one checks out different branches.

  • If two or more Dropbox synced devices have different branches checked out, non committed changes to both devices can be lost,

One way around these issues is to use git worktree to keep branch checkouts in separate directories.


Without using third-party integration tools, I could enhance the condition a bit and use DropBox and other similar cloud disk services such as SpiderOak with Git.

The goal is to avoid the synchronization in the middle of these files modifications, as it can upload a partial state and will then download it back, completely corrupting your git state.

To avoid this issue, I did:

  1. Bundle my git index in one file using git bundle create my_repo.git --all.
  2. Set a delay for the file monitoring, eg 5 minutes, instead of instantaneous. This reduces the chances DropBox synchronizes a partial state in the middle of a change. It also helps greatly when modifying files on the cloud disk on-the-fly (such as with instantaneous saving note-taking apps).

It's not perfect as there is no guarantee it won't mess up the git state again, but it helps and for the moment I did not get any issue.

참고URL : https://stackoverflow.com/questions/1960799/using-git-and-dropbox-together-effectively

반응형