【问题标题】:Can I push/pull directly from my google drive online?我可以直接从我的谷歌驱动器在线推/拉吗?
【发布时间】:2013-04-03 13:44:28
【问题描述】:

有一些方法可以通过 google drive sync windows 应用程序将我的本地 git 存储库同步到我的 google drive,但我想知道我是否可以完全绕过它的需要。

从例如。

$ git remote add origin https://drive.google.com/<my_folder>/<my_repository>.git
$ git push github master

【问题讨论】:

  • 我正在创建这样一个工具....需要更多关于 GIT 服务器的东西。

标签: git google-drive-api


【解决方案1】:

不,你不能。 Google 驱动器上没有运行 git。

我还建议不要使用基于 Google 驱动器/Dropbox 的解决方案,而改用 git 托管解决方案。例如Bitbucket,它提供了一些免费的私有存储库。你可以找到一些关于不同git托管站点here的比较信息。

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

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

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

  • 设备 A 联机 - 您现在在 Google 云端硬盘中存在冲突。

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

【讨论】:

  • 有可能,检查其他答案,接受的答案应该改变。
  • @AmrLotfy 这不可能像 OP 想要的那样。在 Google 驱动器文件夹中拥有裸仓库并不是他所要求的。
  • @user1615903 I would also suggest against Google drive/Dropbox based solutions 为什么会这样?
  • 我正在考虑使用驱动器进行托管,以便在后台同步。 Google Drive 不提供自定义域服务,但我认为 gweb.io 提供。如果我错了,请纠正我。
  • Dropbox 与 git 配合得很好:nssl.noaa.gov/users/lwicker/public_html/…
【解决方案2】:

Here is a very good article关于这个主题(archived version here,相关部分转载在这里):

假设您有一个名为 johndoe 的项目,其文件为 README,如下所示:

/var/www/html/johndoe/
/var/www/html/johndoe/README

在此处初始化一个空的 Git 存储库:

$ cd /var/www/html/johndoe
$ git init
$ git add README
$ git commit README -m "Initial commit."

将目录更改为您的 Google Drive 所在的目录并初始化一个裸存储库:

$ cd /Users/myusername/Google\ Drive/
$ mkdir johndoe
$ cd johndoe
$ git init --bare

回到你的工作目录:

$ cd /var/www/html/johndoe
$ git remote add origin file:///Users/myusername/Google\ Drive/johndoe
$ git push origin master

从 Google Drive 克隆您的 Git 存储库:

$ cd /var/www/html/johndoe2
$ git clone file:///Users/myusername/Google\ Drive/johndoe

【讨论】:

  • 链接的文章是 404'ing。
  • @Michael 存档here
  • @refi64 怎么会这样?我没有看到任何特定于 Windows 的内容。如果有任何关于 Windows 上问题的报告(暗示它适用于 Linux)。
  • 我认为您不需要 file: 限定符 - 所以这可能是上面提到的 Windows 问题?
  • 文章链接打不开@Haralan Dobrev
【解决方案3】:

Eduardo Rosas 有一个article 说明如何使用 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

【讨论】:

    【解决方案4】:

    您可以使用itDuzzit,它们在 Google Drive 和 GitHub 之间提供直接的云到云同步。他们有一个相当有限的free tier 和几个付费的。只要您的代码是开源的和/或您不介意第三方处理它,这可能是一个可行的解决方案。

    【讨论】:

      【解决方案5】:

      如果您正在运行 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
      }
      

      假设您已经运行了git init,您可以从本地项目目录中的命令行输入mkr。在这mkr 步骤之后,您可以像平常一样运行git push,就好像它存在于GitHub、Bitbucket 等上一样。您只是不会从远程获得通常的细节。

      【讨论】:

        【解决方案6】:

        您可以简单地将您认为合适的工作文件夹存档在 Google Drive 上,就像您对任何其他备份一样,为了保持一致性,您可以使用 crontab 或只是一个简单的脚本来自动存档,然后通过 Google Drive cli 工具上传最适合你。

        【讨论】:

        • OP想使用git接口访问google drive,您的建议与他的需求无关。
        • 适用过去时。在满意的 Google Drive 集成可用之前,由用户发布查询以提供支持。
        • “归档工作文件夹”是什么意思?您可以链接到说明吗?什么是“Google Drive cli 工具”?你能链接到解释吗?
        【解决方案7】:

        你可以使用google collab来达到目的。

        • 将文件直接上传到您的谷歌驱动器
        • 打开谷歌协作
        • 导入文件
        • 安装 git(作为 Jupyter 笔记本或 Linux PC)

        你就完成了

        【讨论】:

        • google collab 是否只适用于 Python 代码?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多