【问题标题】:Git - List files recursively by branch/tag nameGit - 按分支/标签名称递归列出文件
【发布时间】:2019-11-12 21:13:57
【问题描述】:

我想在不克隆所有远程文件的情况下查看文件树。是否可以使用 git 命令?

git 版本2.21.0

我当前的命令如下:

- mkdir my-repo && cd my-repo
- git init
- git remote add origin https://remote-repo-url 
- git fetch
- git checkout origin/master -- '*.html'

我怎样才能尽可能快地只获取 .html 文件?我的回购真的很大。我只需要 .html 文件。

【问题讨论】:

    标签: git git-ls-files git-ls-tree


    【解决方案1】:

    对于现有的my-repo,您可以尝试sparse checkout

    echo '*.html' > .git/info/sparse-checkout
    git -c core.sparsecheckout=true checkout origin/master
    

    只有 html 文件及其父文件夹会被留下,其他的会被隐藏。

    如果您需要从头开始,请使用git fetch --depth 1 以最大限度地减少时间和网络成本。

    如果是从头开始的例行任务,可以提前进行镜像克隆,为以后的任务节省时间和空间。

    git clone --mirror https://remote-repo-url -- /path/to/mirror
    

    对于日常任务,

    git clone https://remote-repo-url --reference-if-able /path/to/mirror --depth 1 -- my-repo
    cd my-repo
    echo '*.html' > .git/info/sparse-checkout
    git -c core.sparsecheckout=true checkout origin/master
    

    【讨论】:

    • sparse-checkout 将适用于现有的 repo。但我不想克隆回购。想象一下,我只知道 git-url 和文件名后缀。
    • @zakjma 我能想到的最接近的方法是git archive --remote=https://remote-repo-url -o foo.zip <branch> <paths> 仅下载文件。但是 glob 在这里不起作用。如果您可以提前获取路径列表,它会起作用。在某些情况下,您可能可以访问服务器端存储库以运行git ls-files,或者服务器端存储库有一些服务可以返回路径列表。
    猜你喜欢
    • 2013-09-10
    • 1970-01-01
    • 2012-08-26
    • 1970-01-01
    • 2021-07-21
    • 1970-01-01
    • 1970-01-01
    • 2018-11-27
    • 1970-01-01
    相关资源
    最近更新 更多