我可以直接从谷歌驱动器在线推/拉吗?

lag*_*lex 46 git google-drive-api

有一些方法可以通过谷歌驱动器同步窗口应用程序将我的本地git存储库同步到我的谷歌驱动器,但我想知道我是否可以完全绕过它的需要.

例如.

$ git remote add origin https://drive.google.com/<my_folder>/<my_repository>.git
$ git push github master
Run Code Online (Sandbox Code Playgroud)

161*_*903 40

不,你不能.谷歌硬盘上没有git运行.

我也建议对谷歌驱动器/基于Dropbox的解决方案,并去托管解决方案,而不是一个饭桶.比如Bitbucket提供一些免费的私有存储库.您可以在此处找到有关不同git托管站点的一些比较信息.

正如人们已经指出的那样(并且OP已经知道),您可以将裸存储库放在本地Google Drive/Dropbox文件夹中并使用它,但是,有一些警告.云服务有自己的系统来合并冲突,而这并不适用于git.考虑一下场景:

  • 您使用设备A脱机工作,将一些提交推送到Google云端硬盘文件夹中的裸存储库,但由于您处于脱机状态,这些更改不会同步到云端.

  • 然后你忘了它,在线使用设备B,将提交推送到Google Drive文件夹,这些更改会同步.

  • 设备A变为在线状态 - 您现在在Google云端硬盘中存在冲突.

当然,这是可恢复的,但不方便.因此,我建议使用专为git托管设计的解决方案.

  • 有可能,检查其他答案,接受的答案应该改变. (3认同)

Har*_*rev 20

这是一篇关于这个主题的非常好的文章(这里存档版本,相关部分在这里复制):

假设您有一个以下面johndoe的文件命名的项目README:

/var/www/html/johndoe/
/var/www/html/johndoe/README
Run Code Online (Sandbox Code Playgroud)

在这里初始化一个空的Git存储库:

$ cd /var/www/html/johndoe
$ git init
$ git add README
$ git commit README -m "Initial commit."
Run Code Online (Sandbox Code Playgroud)

将目录更改为Google云端硬盘所在的位置并初始化裸存储库:

$ cd /Users/myusername/Google\ Drive/
$ mkdir johndoe
$ cd johndoe
$ git init --bare
Run Code Online (Sandbox Code Playgroud)

回到你的工作目录:

$ cd /var/www/html/johndoe
$ git remote add origin file:///Users/myusername/Google\ Drive/johndoe
$ git push origin master
Run Code Online (Sandbox Code Playgroud)

要从Google云端硬盘克隆您的Git存储库:

$ cd /var/www/html/johndoe2
$ git clone file:///Users/myusername/Google\ Drive/johndoe
Run Code Online (Sandbox Code Playgroud)

  • 链接的文章是404'ing。 (2认同)
  • @Michael 存档 [此处](https://web.archive.org/web/20161204062829/http://kahthong.com/2012/05/how-use-google-drive-or-dropbox-host-your-private -git-repositories) (2认同)

小智 5

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%23@github.com/LaloCo/handson-ml.git
#I find using a github personal access token easier
!git clone https://user:PAT@github.com/repo
Run Code Online (Sandbox Code Playgroud)