如何从远程Git存储库中获取所有文件及其SHA1的列表? [英] How do i get a list of all the files and their SHA1s from a remote Git repo?

查看:383
本文介绍了如何从远程Git存储库中获取所有文件及其SHA1的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何在远程Git存储库中获得所有文件及其SHA1的列表.

I'm trying to figure out how to get a listing of all the files and their SHA1s in a remote Git repository.

有一种方法可以从本地仓库执行以下操作:

There is a way to do this from a local repo who's command is:

git ls-files * -s

(在示例中)返回以下内容:

Which returns the following (in an example):

100644 1fd148918032743b3b79db573c63a5d453089808 0 2.txt
100644 ff804781c474a06bd055995e48c30799bc6ab65a 0 README

但是这里要注意的是,您必须执行完整的克隆并提前提取所有信息.这不适用于远程存储库的裸克隆.

But the catch here is that you have to perform a full clone and pull all the information down ahead of time. This doesn't work on a bare clone of a remote repository.

有任何线索吗?

推荐答案

所以答案如下(我已经知道了):

So the answer is the following (that i've figured out):

这些步骤假设您的git repo是通过HTTP访问设置的,并且将update-server-info命令设置为接收后挂钩(可能还有其他事情,因为我使用的是github设置的git repo. com). HTTP也可以是HTTPS.

These steps assume your git repo is set up with HTTP access with a update-server-info command set up as a post-receive hook (and possibly other things, as i'm using a git repo set up by github.com). HTTP can also be HTTPS.

  • HTTP GET/info/refs

  • HTTP GET /info/refs

此文件将包含以下内容:

This file will contain something like:

4462ced0a4be2135c009ba6224c2191c7a3f844a    refs/heads/master

  • HTTP GET/objects/44/62ed0a4be2135c009ba6224c2191c7a3f844a

  • HTTP GET /objects/44/62ed0a4be2135c009ba6224c2191c7a3f844a

    使用zlib解压缩该文件.

    Decompress this file using zlib.

    此文件将包含以下内容:

    This file will contain something like:

        commit 219
        tree 0d4f34f97d76e54666751a850e9300e8b23c1adb
        parent fca1c898e2b4a43c66f211bd3547dc301511721d
        author yourname <yourname@email.com> 1295905469 -0800
        committer yourname <yourname@email.com> 1295905469 -0800
    
        added a/a.txt.
    

  • 将树SHA1放在顶部.

  • Take the tree SHA1 at the top.

    HTTP GET/objects/0d/4f34f97d76e54666751a850e9300e8b23c1adb

    HTTP GET /objects/0d/4f34f97d76e54666751a850e9300e8b23c1adb

    使用zlib解压缩该文件.

    Decompress this file with zlib.

    此文件将包含以下内容:

    This file will contain something like:

        Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    
        00000000  74 72 65 65 20 39 35 00 31 30 30 36 34 34 20 32  tree 95.100644 2
        00000010  2E 74 78 74 00 1F D1 48 91 80 32 74 3B 3B 79 DB  .txt..ÑH‘€2t;;yÛ
        00000020  57 3C 63 A5 D4 53 08 98 08 31 30 30 36 34 34 20  W<c¥ÔS.˜.100644 
        00000030  52 45 41 44 4D 45 00 FF 80 47 81 C4 74 A0 6B D0  README.ÿ€G.Ät kÐ
        00000040  55 99 5E 48 C3 07 99 BC 6A B6 5A 34 30 30 30 30  U™^HÃ.™¼j¶Z40000
        00000050  20 61 00 1A 60 2D 9B D0 7C E5 27 2D DA A6 4E 21   a..`-›Ð|å'-Ú¦N!
        00000060  DA 12 DB CA 2B 8C 9F                             Ú.ÛÊ+ŒŸ
    

    此文件的格式如下:

        tree<space>##<NULL><object type id><space><filename><NULL><SHA1>
    

    此模式不断重复.

    从此示例中获取第一个SHA1(1fd148918032743b3b79db573c63a5d453089808).

    Take the first SHA1 from this example (1fd148918032743b3b79db573c63a5d453089808).

    HTTP GET/objects/1f/d148918032743b3b79db573c63a5d453089808

    HTTP GET /objects/1f/d148918032743b3b79db573c63a5d453089808

    使用zlib解压缩该文件.

    Decompress this file with zlib.

    此文件将包含以下内容:

    This file will contain something like the following:

        Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    
        00000000  62 6C 6F 62 20 36 00 61 64 73 66 0A 32           blob 6.adsf.2
    

    那里有单个文件的内容(您一直在跟踪谁的路径,以及您从以前的树状列表中知道的名字).该文件带有一些元信息的前缀,在这种情况下为:

    And there you have the content of an individual file (who's path you've been keeping track of, and who's name you know from the tree listing previously). This file is prefixed with some meta-information, which in this case is:

    blob 6<NULL><file content>
    

  • 注意:如果所需文件位于存储库根目录的子目录中,则树对象文件中的条目将具有树的对象类型ID(在本例中为040000).您可以采用该树对象的SHA1,通过HTTP GET该对象,然后将其解压缩,查看内容,然后重复该过程,直到向下钻取到所需文件为止,然后使用它的SHA1获取文件内容(就像上一个步骤),然后就可以了.

    Note: If the file you want is in a subdirectory of the root of the repo, the entry in the tree object file will have an object type id of a tree (which appears in this case to be 040000). You can take the SHA1 of that tree object, HTTP GET that object, then decompress it, view the contents, and repeat that process until you drill down to the file you want, then get the file contents using it's SHA1 (like in the last step), and there you go.

    这篇关于如何从远程Git存储库中获取所有文件及其SHA1的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆