views:

139

answers:

3

Using the OS X terminal,

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

+3  A: 

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.

Jakub Narębski
A: 

Look at

http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#object-details

it is raw compressed data using zlib. One can use 'zpipe' from the 'zlib1g-dev' package (compile the example with 'gcc -o zpipe zpipe.c -lz'). It is not a standard .gz or something.

$ ./zpipe -d < .git/objects/02/43019ddb4d94114e5a8580eec01baeea195133

prints the content of the blob (header+data)

If you want to check the sha-1, you have to put the uncompressed blob in a file (myblob) and do

$ sha1sum myblob

xof
A: 

I'm going to interpret your question in a different way. If you want to understand what the objects files ARE, you can use git to view them directly, without navigating the history log or using git checkout, diff etc. For instance:

For the file .git/objects/04/a42e9a7282340ef0256eaa6d59254227b8b141

Run the command

git show 04a42e

which combines the 04 from /04/ and the first four characters of the remaining number a42e.

> git show 04a42e
commit 04f7db976fa54c72fcc6350dd7d0aa06cb249df6
Author: Alex Brown <[email protected]>
Date:   Fri Jan 8 11:02:21 2010 +0000
a text file

diff --git a/1.txt b/1.txt
new file mode 100644
index 0000000..04a42e9
--- /dev/null
+++ b/1.txt
@@ -0,0 +1,3 @@
+Woo
+# boo
+# choo

This one is a commit, other objects may be file blobs, trees, etc.

Alex Brown