【问题标题】:Download files from git repo on linux server从 Linux 服务器上的 git repo 下载文件
【发布时间】:2017-03-24 18:19:21
【问题描述】:

我看过很多关于如何从 git repo 下载特定文件的文章/问题,但似乎没有一个与我的情况相符。


  • 我需要什么

使用来自 linux 服务器的 http 或 ssh 从私有 git 存储库下载特定文件

【问题讨论】:

    标签: linux git bash github continuous-deployment


    【解决方案1】:

    更新 - 我最初写这篇文章是作为关于 git 的一般答案,并将在下面保留该信息。但我看到你在谈论 github,它确实提供了一些额外的选项。

    例如,您可以使用类似的命令

    curl https://raw.githubusercontent.com/eirslett/frontend-maven-plugin/master/README.md > README.md
    

    仅从 frontend-maven-plugin 下载 README.md(我刚刚正在查看)。

    您提到您的仓库是私人仓库,因此您必须处理身份验证;我建议阅读 curl,因为它应该能够为 repo 提供凭据。

    https://curl.haxx.se/docs/manpage.html

    原答案

    实际上并没有一个 git 命令可以从远程 git 存储库中下载单个文件。我知道你能做的最接近的是:

    首先克隆 repo 而不检查工作树

    git clone -n <repo-url>
    

    然后只检查你想要的文件

    git checkout master -- path/within/repo/to/file
    

    但不要上当:这仍然会下载整个 repo。 (这就是 git 的工作方式。)因此,除了获取 ./path/within/repo/to/file 之外,您还获得了包含所有其余数据的 ./.git。

    【讨论】:

      【解决方案2】:

      你可以用这种骇人听闻的方式来做:ö(å_å)ö

      如果此文件在 github.com 上,请执行此操作。:

      wget https://example.githubproject.com/user/project/master/README
      

      你可以试试git归档命令

      git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)
      

      在当前分支上创建一个包含最新提交内容的 tar 存档,并将其解压到 /var/tmp/junk 目录中。

      git archieve 命令用法示例:

      git archive --format=tar --remote=origin HEAD | tar xf -
      git archive --format=tar --remote=origin HEAD <file> | tar xf -
      

      提示使用,git archiveExamples

      【讨论】:

        【解决方案3】:

        我不确定你的问题是什么,但是,你有没有 git clone &lt;&lt;url of git project&gt;&gt;

        【讨论】:

        • 问题:我需要将特定文件从 git 存储库从 linux 服务器下载到特定目录
        • 这真的是评论,而不是答案。多一点 rep 你就可以发布 cmets
        • 对不起@LibinVarghese
        猜你喜欢
        • 2013-06-04
        • 1970-01-01
        • 1970-01-01
        • 2021-09-28
        • 1970-01-01
        • 2011-04-09
        相关资源
        最近更新 更多