【问题标题】:Initialise GitHub repo from RStudio without Using Command Line不使用命令行从 RStudio 初始化 GitHub 存储库
【发布时间】:2020-03-27 06:14:08
【问题描述】:

我的任务是在我的工作地点测试 GitHub 培训计划的可行性。由于内部安全,我们无法使用命令行。我正在尝试:

  • 初始化一个新的 git 存储库
  • 从我当前的 R 项目中添加文件
  • 提交这些暂存文件
  • 推送到新创建的 GitHub 存储库

所有来自 RStudio 使用 git2r 函数。

我在网上找到的每个教程都依赖于命令行或着眼于克隆现有存储库。我找不到任何从本地 r 项目创建存储库的过程。

目前的工作流程如下所示:

library(git2r)

repo <- init("C:/local_folder/r_project_folder")

config(repo, user.name, user.email)

cred <- cred_token() # Git PAT is included in the projects renviron file

add(repo, "*")

commit(repo, "Commit message")

push()

返回错误信息:

 Error in 'git2r_push': remote 'origin' does not exist

如果只是一个综合教程的链接,那将对我有所帮助。 git2r README 侧重于连接到现有的 repos。

【问题讨论】:

  • 你不能创建一个 repo 然后将该 repo 克隆到本地机器吗?然后从那里,因为它已连接,您可以直接推送到 git。你不必使用命令行,它只需要你在弄乱 r 之前创建 repo。
  • 我认为您对 git 与 GitHub 有点混淆。你在本地有一个 git repo。推送意味着您将该存储库及其历史复制到其他平台,在本例中为 GitHub 网站。如果没有远程设置,则无处可推。 GitHub 是托管和共享存储库的几个选项之一,但不是 git 的同义词
  • Happy Git with R 一书中有一个章节:happygitwithr.com/rstudio-git-github.html
  • 说他可以通过 GitHub 创建一个 git repo,将该 git repo 复制到他的本地机器,添加文件,然后推送回 GitHub 是否正确?抱歉,只是想了解确切的术语。
  • Camille - 现在我遇到了这个问题,但不幸的是,以这种方式创建 GitHub 存储库需要命令行提示符,正如我所提到的,该命令行提示符被禁用。我可以按照 Hansel 的建议将现有的空仓库克隆到新文件夹中吗?尝试从 R 项目文件夹执行此操作失败并显示错误消息,由于目标不是“空”,这是不可能的

标签: r git github rstudio


【解决方案1】:

您遇到的错误是因为您没有提供 git 推送到的位置。

我认为您正在寻找 remotes 命令 - https://www.rdocumentation.org/packages/git2r/versions/0.23.0/topics/remotes

您可以为此提供本地文件夹路径,它不必是远程服务器。

【讨论】:

    【解决方案2】:

    使用一点谷歌和一点 Hansel Palencias 的建议解决了:

    首先在您的存储库页面上创建一个空的 GitHub 存储库,然后输入以下命令:

    # Clone existing github repo using url and linking this to your project path
    clone(url = "https://github.com/user/name_of_repo.git", local_path = "path")
    
    setwd("path")
    
    # Assign variable repo as current local repository
    repo <- repository()
    
    # Configure access rights with github username and profile
    config(repo, user.name='user name', user.email='email address')
    
    # Add a PAT in local renviron folder
    edit_r_environ()
    
    # Save PAT as cred token
    cred <- cred_token()
    
    # Stage changs to commit
    add(repo, "file.R")
    commit(repo, "Commit message")
    
    # Push changes
    push(repo, 'origin', 'refs/heads/master', credentials = cred)
    

    有点破解,但解决了问题。将尝试按照建议使用 remotes() 命令作为更有效的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-31
      • 2020-06-30
      • 2021-06-01
      • 2013-08-10
      • 1970-01-01
      • 2020-01-05
      • 1970-01-01
      相关资源
      最近更新 更多