【问题标题】:How can I download the most recent version of a GitHub project to use in a bash script?如何下载 GitHub 项目的最新版本以在 bash 脚本中使用?
【发布时间】:2013-03-06 10:05:54
【问题描述】:

我正在编写一个设置 CMS (Statamic) 的脚本,以便开发人员可以直接开始编写代码,而不必手动移动内容、从 GitHub 收集常用代码等等。

我需要一种方法从 GitHub 获取项目的最新版本,将其解压缩,并且能够在不知道最新 sha 的情况下移动内容。

【问题讨论】:

    标签: bash github


    【解决方案1】:

    代码

    # Download most recent version from GitHub
    curl -L -o DOWNLOADED_FILE_NAME.zip https://api.github.com/repos/USER/REPO/zipball/BRANCH
    unzip DOWNLOADED_FILE_NAME.zip
    # Find out the name of the unzipped dir and assign it to a variable.
    UNZIPPED_DIR=$(compgen -A builtin -f USER-REPO)
    rm DOWNLOADED_FILE_NAME.zip
    

    说明

    • -L 告诉 curl 跟随重定向。
    • -o 指定下载文件的名称。
    • 阅读本文以获取info 从命令行下载 GitHub 文件。
    • 有关 compgen 的信息,请查看 this answer 另一个问题。

    【讨论】:

      猜你喜欢
      • 2015-03-29
      • 1970-01-01
      • 2014-02-21
      • 1970-01-01
      • 2014-07-27
      • 1970-01-01
      • 1970-01-01
      • 2021-08-06
      • 1970-01-01
      相关资源
      最近更新 更多