【问题标题】:How can I pull a single file from an external repository into my current project?如何将外部存储库中的单个文件提取到当前项目中?
【发布时间】:2020-04-07 09:42:18
【问题描述】:

有没有办法将特定的.gitignore 从外部存储库拉到我当前的项目中?

在这种情况下,我想从 this Github repository 中提取 Python .gitignore 文件,但似乎找不到方法。

如果可能的话,我想这对于未来的项目来说是非常有用的学习内容。

有可能吗?

【问题讨论】:

  • 如果你专门去 GitHub 获取一个特定的文件,有一种 GitHub 特定的方法可以直接执行此操作。不过,您使用了[git] 标签而不是[github] 标签,请参阅Saurabh P Bhandari's answer
  • 此实例直接与 GitHub 相关,但问题通常与 git 相关;如何实现“Github 方式”? [github] 标签添加到问题。

标签: git github


【解决方案1】:

在您当前的项目中,运行以下命令:

# Add external repo as remote (named "upstream")
git remote add upstream https://github.com/github/gitignore.git
#                       ^         <external repo url>         ^

# Fetch the external repo
git fetch upstream

# Checkout the particular file from the remote repo
git checkout upstream/master -- Python.gitignore
#           <remote>/<branch>    <path/to/file>  

# Commit the changes in your local repo
git commit

参考文献:

【讨论】:

    【解决方案2】:

    GitHub 特定方法(作为单独的问题可能更好,但请参阅下面的另见参考):

    如果您点击your own link 并查看显示文件内容窗格的右侧,您将看到一排标记为rawblame的可点击框> 和 history(后面是可点击的图标)。单击标有 RAW 的那个会得到 URL https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore

    另见What do raw.githubusercontent.com URLs represent?

    【讨论】:

      猜你喜欢
      • 2017-07-20
      • 1970-01-01
      • 2020-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-14
      • 2019-03-09
      • 1970-01-01
      相关资源
      最近更新 更多