git 我可以直接从我的谷歌驱动器在线推/拉吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15947502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I push/pull directly from my google drive online?
提问by laggingreflex
There are methods to sync my local git repository over to my google drive via google drive sync windows application, but I was wondering whether I could bypass its need altogether.
有一些方法可以通过谷歌驱动器同步 Windows 应用程序将我的本地 git 存储库同步到我的谷歌驱动器,但我想知道我是否可以完全绕过它的需要。
Fro eg.
从例如。
$ git remote add origin https://drive.google.com/<my_folder>/<my_repository>.git
$ git push github master
采纳答案by 1615903
No, you can't. There's no git running on Google drive.
不,你不能。Google 驱动器上没有运行 git。
I would also suggest against Google drive/Dropbox based solutions, and go for a git hosting solution instead. For example Bitbucketwhich offers some free private repositories. You can find some comparison information about different git hosting sites here.
我还建议不要使用基于 Google Drive/Dropbox 的解决方案,而是使用 git 托管解决方案。例如Bitbucket,它提供了一些免费的私有存储库。您可以在此处找到有关不同 git 托管站点的一些比较信息。
As people have pointed out (and as OP already knows), you can put the bare repository inside your local Google Drive/Dropbox folder and work with that, however, there are caveats. The cloud services have their own systems for merging conflicts, and that doesn't really work with git. Consider the scenario:
正如人们所指出的(正如 OP 已经知道的那样),您可以将裸存储库放在本地 Google Drive/Dropbox 文件夹中并使用它,但是,有一些注意事项。云服务有自己的系统来合并冲突,这对 git 来说并不真正有效。考虑以下场景:
You work with device A offline, push some commits to the bare repository in Google Drive folder, but because you are offline, those changes do not sync to the cloud.
You then forget about it, work with device B online, push commits to Google Drive folder, and those changes do get synced.
Device A becomes online - you now have a conflict in Google Drive.
您离线使用设备 A,将一些提交推送到 Google Drive 文件夹中的裸存储库,但由于您处于离线状态,这些更改不会同步到云。
然后你忘记它,在线使用设备 B,将提交推送到 Google Drive 文件夹,这些更改确实会同步。
设备 A 联机 - 您现在在 Google 云端硬盘中存在冲突。
This is, of course, recoverable, but inconvenient. I therefore recommend to use a solution that is designed precisely for git hosting.
这当然是可以恢复的,但不方便。因此,我建议使用专为 git 托管设计的解决方案。
回答by Haralan Dobrev
Here is a very good articleon the subject (archived version here, with the relevant parts reproduced here):
这是一篇关于该主题的非常好的文章(此处为存档版本,此处转载了相关部分):
Lets say you have a project named johndoe
with a file README
like below:
假设您有一个以johndoe
文件命名的项目,README
如下所示:
/var/www/html/johndoe/
/var/www/html/johndoe/README
Initialise an empty Git repository here:
在此处初始化一个空的 Git 存储库:
$ cd /var/www/html/johndoe
$ git init
$ git add README
$ git commit README -m "Initial commit."
Change the directory to where your Google Drive is located and initialize a bare repository:
将目录更改为您的 Google Drive 所在的目录并初始化一个裸存储库:
$ cd /Users/myusername/Google\ Drive/
$ mkdir johndoe
$ cd johndoe
$ git init --bare
Go back to your working directory:
回到你的工作目录:
$ cd /var/www/html/johndoe
$ git remote add origin file:///Users/myusername/Google\ Drive/johndoe
$ git push origin master
To clone your Git repository from Google Drive:
要从 Google Drive 克隆您的 Git 存储库:
$ cd /var/www/html/johndoe2
$ git clone file:///Users/myusername/Google\ Drive/johndoe
回答by A.R.
You could use itDuzzit, they provide direct cloud-to-cloud syncing between Google Drive and GitHub. They have a fairly limited free tierand several paid ones. As long as your code is opensource and/or you don't mind a third-party handling it, this could be a viable solution.
您可以使用itDuzzit,它们在 Google Drive 和 GitHub 之间提供直接的云到云同步。他们有一个相当有限的免费层和几个付费层。只要您的代码是开源的和/或您不介意第三方处理它,这可能是一个可行的解决方案。
回答by bholben
If you are running a Unix shell and have Google Drive locally installed on your machine, you can add a script to your .bash_profile or .zshrc file like this...
如果您正在运行 Unix shell 并且在您的机器上本地安装了 Google Drive,您可以将脚本添加到您的 .bash_profile 或 .zshrc 文件中,如下所示...
# Initialize a remote repo on "local" Google Drive and push to it for safekeeping.
function mkr() {
CWD=$(PWD)
REPONAME=${PWD##*/}
REPOPATH=/Users/Bob/Google\ Drive/Repos/$REPONAME
mkdir -p $REPOPATH
cd $REPOPATH
git init --bare
cd $CWD
git remote add origin $REPOPATH
git push origin master
}
Assuming you have already run git init
, you can type mkr
from the command line inside your local project directory. After this mkr
step, you can run git push
like normal as if it lives on GitHub, Bitbucket, etc. You just won't have the usual niceties from the remote side.
假设您已经运行了git init
,您可以mkr
从本地项目目录中的命令行输入。在这mkr
一步之后,你可以git push
像平常一样运行,就像它存在于 GitHub、Bitbucket 等上一样。你只是不会从远程端获得通常的细节。
回答by Spencer
You could simply archive your working folders as you see fit on Google Drive as you would any other backup , for the sake of consistency you can automate this with crontab or just a simple script to archive then upload via Google Drive cli tools that work best for you.
您可以简单地将您认为合适的工作文件夹归档在 Google Drive 上,就像任何其他备份一样,为了保持一致性,您可以使用 crontab 自动执行此操作,或者只是一个简单的脚本进行归档,然后通过最适合的 Google Drive cli 工具上传你。
回答by rwreed
Eduardo Rosas has an articleon how to do this using colab (only a browser required).
essentially you access your google drive using:
Eduardo Rosas 有一篇关于如何使用 colab 执行此操作的文章(仅需要浏览器)。基本上您可以使用以下方式访问您的谷歌驱动器:
from google.colab import drive
drive.mount('/content/gdrive')
#cd to the google drive you using the magic command
%cd /content/gdrive/'My Drive'/[your drive folder for repo]
#check your directory location with
!pwd
#clone your repo - Note this exposes your password so don't make the notebook public
!git clone https://LaloCo:password%[email protected]/LaloCo/handson-ml.git
#I find using a github personal access token easier
!git clone https://user:[email protected]/repo