How to view git objects and index without using git

后端 未结 5 2282
情歌与酒
情歌与酒 2020-12-29 07:13

Using the OS X terminal,

How an you view the contents of these files as plain text?

5条回答
  •  旧时难觅i
    2020-12-29 07:56

    If you want to view plain text form of git objects (commits and/or blobs i.e. file contents) without using git, it would not be easy, especially if repository is packed. Can't you install git locally, in your home directory (or its equivalent on MacOS X)?

    The format for loose objects, stored as files in .git/objects/ fan-out directory, e.g. .git/objects/02/43019ddb4d94114e5a8580eec01baeea195133 (the fan-out directory and file name form SHA-1 identifier of object), is described e.g. in Chapter 9.2 "Git Objects" of "Pro Git" book (available on-line for free) and Chapter 7.1 "How Git Stores Objects" of "Git Community Book".

    The pack format, where set of objects is stored in single file in .git/objects/pack/, e.g. .git/objects/pack/pack-1db7aa96d95149a4dd341490a3594181a24415ee.pack, is described in Documentation/technical/pack-format.txt and in Chapter 7.5 "The Packfile" of "Git Community Book" (and mentioned in Chapter 9.4 "Packfiles" of "Pro Git")


    If you want to find latest commit, take a look first at .git/HEAD file to find current branch. It would contain something like the following:

    ref: refs/heads/master
    

    (if it contains SHA-1, you can take it as id of last commit, and skip a step). Then check e.g. .git/refs/heads/master to find where the branch points to. It would contain SHA-1 of a commit, e.g.:

    dbc1b1f71052c084a84b5c395e1cb4b5ae526fcb
    

    Last (most recent) commit would be probably in loose format; in this example it would be in .git/objects/db/c1b1f71052c084a84b5c395e1cb4b5ae526fcb file.

提交回复
热议问题