【问题标题】:How do I get the raw version of a gist from github?如何从 github 获取原始版本的要点?
【发布时间】:2021-06-26 19:49:03
【问题描述】:

我需要从原始 gist 加载 shell 脚本,但我找不到获取原始 URL 的方法。

curl -L address-to-raw-gist.sh | bash

【问题讨论】:

标签: gist


【解决方案1】:

还有,寻找raw 按钮(在源代码的右上角)。

原始 URL 应如下所示:

https://gist.githubusercontent.com/{user}/{gist_hash}/raw/{commit_hash}/{file}

注意:省略{commit_hash}部分可以获取最新版本,如下图:

https://gist.githubusercontent.com/{user}/{gist_hash}/raw/{file}

【讨论】:

【解决方案2】:

2014 年 2 月:原始网址刚刚更改。
见“Gist raw file URI change”:

所有 Gist 文件的原始主机正在立即更改。
进行此更改是为了进一步将用户内容与受信任的 GitHub 应用程序隔离开来。

新主机是

 https://gist.githubusercontent.com. 

现有的 URI 将重定向到新主机。

之前是https://gist.github.com/<username>/<gist-id>/raw/...

现在是https://gist.githubusercontent.com/<username>/<gist-id>/raw/...

例如:

https://gist.githubusercontent.com/VonC/9184693/raw/30d74d258442c7c65512eafab474568dd706c430/testNewGist

KrisWebDev 添加in the comments

如果您想要 Gist 文档的最新版本,只需从 URL 中删除 <commit>/

https://gist.githubusercontent.com/VonC/9184693/raw/testNewGist

【讨论】:

  • @KrisWebDev 好点。我在答案中包含了更多可见性以及一个示例。
  • The raw host for all Gist files is changing immediately. 但我没有立即找到
  • 更好的方法是关注 API:api.github.com/gists/9184693 您可以从那里获取 raw_url 并使用它。毫无疑问,这个答案是正确的,但 API 将(永远)过时,他们可能会像 2014 年 2 月那样再次更改它。
【解决方案3】:

可以简单地使用 github api。

https://api.github.com/gists/$GIST_ID

参考:https://miguelpiedrafita.com/github-gists

【讨论】:

  • 此 API 返回 JSON 数据,您可以从中获取原始 URL,如下所示:url = json_data["files"][filename]["raw_url"] 其中filename 是 gist 中特定文件的名称。
【解决方案4】:

Gitlab sn-ps 提供简洁的 url,易于创建并且与命令行配合良好。

示例:通过修补 /etc/bash.bashrc 启用 bash 完成

sudo su -
(curl -s https://gitlab.com/snippets/21846/raw && echo) | patch -s /etc/bash.bashrc

【讨论】:

    猜你喜欢
    • 2022-01-26
    • 2013-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    • 2016-06-30
    • 2012-06-25
    相关资源
    最近更新 更多