Git和Dropbox可以一起使用吗?
当前回答
在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\""
其他回答
在我看来,Dropbox只适用于个人用途,因为你不想麻烦地获得一个中央回收主机。对于任何专业开发来说,你可能会制造更多的问题,而不是解决更多的问题,就像已经在帖子中多次提到的那样,Dropbox并不是为这个用例而设计的。也就是说,在没有任何第三方插件或工具的情况下,在Dropbox上转储存储库的一个非常安全的方法是使用捆绑包。我在我的.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
还有一个开源项目(一个跨平台[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和手册以获得完整的命令参考和教程。
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,但这个经验告诉我们,如果你在不同的时间从不同的机器(对我来说是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除了风险什么都不会增加。不要这样做。
我喜欢丹·麦克内文投票最多的回答。我最后做了太多次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主分支。如果给出了多个项目名称,则将使用最右边的项目名称参数。
可选地,-r命令参数指定将推送到源主机的远程分支。项目起源主节点的位置也可以用-m参数指定。一个默认的.gitignore文件也放置在远程分支目录中。目录和.gitignore文件默认值在脚本中指定。
推荐文章
- 如何将Git分支移到它自己的存储库中?
- 如何禁用Git凭证管理器的Windows?
- Git 拉取与 Git 变基
- 在git中压缩提交是什么意思?
- 在GIT中合并2个分支
- git标签也会被推送吗?
- 嵌套的Git存储库?
- Git bash错误:无法fork子进程:没有可用的终端(-1)
- 有没有办法在SourceTree中获得两个分支的视觉差异?
- Git标记是否只应用于当前分支?
- Git分支:master vs. origin/master vs. remotes/origin/master
- 如何根据文件扩展名过滤git差异?
- 如何设置一个git项目使用外部回购子模块?
- Git同时在两个分支上工作
- 如何在Visual Studio中删除未推送的外向提交?