11 For a better understanding of Dulwich, we'll start by explaining most of the
14 Open the ".git" folder of any Git-managed repository. You'll find folders
15 like "branches", "hooks"... We're only interested in "objects" here. Open it.
17 You'll mostly see 2 hex-digits folders. Git identifies content by its SHA-1
18 digest. The 2 hex-digits plus the 38 hex-digits of files inside these folders
19 form the 40 characters (or 20 bytes) id of Git objects you'll manage in
22 We'll first study the three main objects:
33 You're used to generate commits using Git. You have set up your name and
34 e-mail, and you know how to see the history using "git log".
36 A commit file looks like this::
38 commit <content length><NUL>tree <tree sha>
40 [parent <parent sha> if several parents from merges]
41 author <author name> <author e-mail> <timestamp> <timezone>
42 committer <author name> <author e-mail> <timestamp> <timezone>
46 But where are the changes you commited? The commit contains a reference to a
52 A tree is a collection of file information, the state of your working copy at
53 a given point in time.
55 A tree file looks like this::
57 tree <content length><NUL><file mode> <filename><NUL><blob sha>...
59 And repeats for every file in the tree. A real example from Dulwich itself::
61 Note that for a unknown reason, the SHA-1 digest is in binary form here.
63 The file mode is like the octal argument you could give to the "chmod"
64 command. Except it is in extended form to tell regular files from
65 directories and other types.
67 We now know how our files are referenced but we haven't found their actual
68 content yet. That's where the reference to a blob comes in.
73 A blob is simply the content of files you are versionning.
75 A blob file looks like this::
77 blob <content length><NUL><content>
79 If you change a single line, another blob will be generated by Git at commit
80 time. This is how Git can fastly checkout any version in time.
82 On the opposite, several identical files with different filenames generate
83 only one blob. That's mostly how renames are so cheap and efficient in Git.
88 Dulwich implements these three objects with an API to easily access the
89 information you need, while abstracting some more secrets Git is using to
90 accelerate operations and reduce space.
92 More About Git formats
93 ----------------------
95 These three objects make 90 % of a Git repository. The rest is branch
96 information and optimizations.
98 For instance there is an index of the current state of the working copy.
99 There are also pack files to group several small objects in a single indexed
102 You'll find more detailled explanations and examples here:
103 http://www-cs-students.stanford.edu/~blynn/gitmagic/ch08.html
105 Just note that recent versions of Git compress object files using zlib.