summaryrefslogtreecommitdiff
path: root/.html/git/theory-and-practice/objects.html
diff options
context:
space:
mode:
Diffstat (limited to '.html/git/theory-and-practice/objects.html')
-rw-r--r--.html/git/theory-and-practice/objects.html202
1 files changed, 202 insertions, 0 deletions
diff --git a/.html/git/theory-and-practice/objects.html b/.html/git/theory-and-practice/objects.html
new file mode 100644
index 0000000..ff6c53b
--- /dev/null
+++ b/.html/git/theory-and-practice/objects.html
@@ -0,0 +1,202 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>
+ The Codex »
+ Objects
+ </title>
+
+ <link
+ rel='stylesheet'
+ type='text/css'
+ href='http://fonts.googleapis.com/css?family=Buenard:400,700&amp;subset=latin,latin-ext'>
+ <link
+ rel="stylesheet"
+ type="text/css"
+ href="../../media/css/reset.css">
+ <link
+ rel="stylesheet"
+ type="text/css"
+ href="../../media/css/grimoire.css">
+</head>
+<body>
+
+<div id="shell">
+
+ <ol id="breadcrumbs">
+
+ <li class="crumb-0 not-last">
+
+ <a href="../../">index</a>
+
+ </li>
+
+ <li class="crumb-1 not-last">
+
+ <a href="../">git</a>
+
+ </li>
+
+ <li class="crumb-2 not-last">
+
+ <a href="./">theory-and-practice</a>
+
+ </li>
+
+ <li class="crumb-3 last">
+
+ objects
+
+ </li>
+
+ </ol>
+
+
+
+ <div id="article">
+ <h1 id="objects">Objects</h1>
+<p>Git's basest level is a storage and naming system for things Git calls
+“objects.” These objects hold the bulk of the data about files and projects
+tracked by Git: file contents, directory trees, commits, and so on. Every
+object is identified by a SHA-1 hash, which is derived from its contents.</p>
+<p>SHA-1 hashes are obnoxiously long, so Git allows you to substitue any unique
+prefix of a SHA-1 hash, so long as it's at least four characters long. If the
+hash <code>0b43b9e3e64793f5a222a644ed5ab074d8fa1024</code> is present in your repository,
+then Git commands will understand <code>0b43</code>, <code>0b43b9</code>, and other patterns to all
+refer to the same object, so long as no other object has the same SHA-1
+prefix.</p>
+<h2 id="blobs">Blobs</h2>
+<p>The contents of every file that's ever been stored in a Git repository are
+stored as <code>blob</code> objects. These objects are very simple: they contain the file
+contents, byte for byte.</p>
+<h2 id="trees">Trees</h2>
+<p>File contents (and trees, and Other Things we'll get to later) are tied
+together into a directory structure by <code>tree</code> objects. These objects contain a
+list of records, with one child per record. Each record contains a permissions
+field corresponding to the POSIX permissions mask of the object, a type, a
+SHA-1 for another object, and a name.</p>
+<p>A directory containing only files might be represented as the tree</p>
+<pre><code>100644 blob 511542ad6c97b28d720c697f7535897195de3318 config.md
+100644 blob 801ddd5ae10d6282bbf36ccefdd0b052972aa8e2 integrate.md
+100644 blob 61d28155862607c3d5d049e18c5a6903dba1f85e scratch.md
+100644 blob d7a79c144c22775239600b332bfa120775bab341 survival.md
+</code></pre>
+<p>while a directory with subdirectories would also have some <code>tree</code> children:</p>
+<pre><code>040000 tree f57ef2457a551b193779e21a50fb380880574f43 12factor
+040000 tree 844697ce99e1ef962657ce7132460ad7a38b7584 authnz
+100644 blob 54795f9b774547d554f5068985bbc6df7b128832 cool-urls-can-change.md
+040000 tree fc3f39eb5d1a655374385870b8be56b202be7dd8 dev
+040000 tree 22cbfb2c1d7b07432ea7706c36b0d6295563c69c devops
+040000 tree 0b3e63b4f32c0c3acfbcf6ba28d54af4c2f0d594 git
+040000 tree 5914fdcbd34e00e23e52ba8e8bdeba0902941d3f java
+040000 tree 346f71a637a4f8933dc754fef02515a8809369c4 mysql
+100644 blob b70520badbb8de6a74b84788a7fefe64a432c56d packaging-ideas.md
+040000 tree 73ed6572345a368d20271ec5a3ffc2464ac8d270 people
+</code></pre>
+<h2 id="commits">Commits</h2>
+<p>Blobs and trees are sufficient to store arbitrary directory trees in Git, and
+you could use them that way, but Git is mostly used as a revision-tracking
+system. Revisions and their history are represented by <code>commit</code> objects, which contain:</p>
+<pre><code>* The SHA-1 hash of the root `tree` object of the commit,
+* Zero or more SHA-1 hashes for parent commits,
+* The name and email address of the commit's “author,”
+* The name and email address of the commit's “committer,”
+* Timestamps representing when the commit was authored and committed, and
+* A commit message.
+</code></pre>
+<p>Commit objects' parent references form a directed acyclic graph; the subgraph
+reachable from a specific commit is that commit's <em>history</em>.</p>
+<p>When working with Git's user interface, commit parents are given in a
+predictable order determined by the <code>git checkout</code> and <code>git merge</code> commands.</p>
+<h2 id="tags">Tags</h2>
+<p>Git's revision-tracking system supports “tags,” which are stable names for
+specific configurations. It also, uniquely, supports a concept called an
+“annotated tag,” represented by the <code>tag</code> object type. These annotated tag
+objects contain</p>
+<pre><code>* The type and SHA-1 hash of another object,
+* The name and email address of the person who created the tag,
+* A timestamp representing the moment the tag was created, and
+* A tag message.
+</code></pre>
+<h2 id="anonymity">Anonymity</h2>
+<p>There's a general theme to Git's object types: no object knows its own name.
+Every object only has a name in the context of some containing object, or in
+the context of <a href="refs-and-names">Git's refs mechanism</a>, which I'll get to
+shortly. This means that the same <code>blob</code> object can be reused for multiple
+files (or, more probably, the same file in multiple commits), if they happen
+to have the same contents.</p>
+<p>This also applies to tag objects, even though their role is part of a system
+for providing stable, meaningful names for commits.</p>
+<h2 id="examining-objects">Examining objects</h2>
+<ul>
+<li>
+<p><code>git cat-file &lt;type&gt; &lt;sha1&gt;</code>: decodes the object <code>&lt;sha1&gt;</code> and prints its
+ contents to stdout. This prints the object's contents in their raw form,
+ which is less than useful for <code>tree</code> objects.</p>
+</li>
+<li>
+<p><code>git cat-file -p &lt;sha1&gt;</code>: decodes the object <code>&lt;sha1&gt;</code> and pretty-prints it.
+ This pretty-printing stays close to the underlying disk format; it's most
+ useful for decoding <code>tree</code> objects.</p>
+</li>
+<li>
+<p><code>git show &lt;sha1&gt;</code>: decodes the object <code>&lt;sha1&gt;</code> and formats its contents to
+ stdout. For blobs, this is identical to what <code>git cat-file blob</code> would do,
+ but for trees, commits, and tags, the output is reformated to be more
+ readable.</p>
+</li>
+</ul>
+<h2 id="storage">Storage</h2>
+<p>Objects are stored in two places in Git: as “loose objects,” and in “pack
+files.” Newly-created objects are initially loose objects, for ease of
+manipulation; transferring objects to another repository or running certain
+administrative commands can cause them to be placed in pack files for faster
+transfer and for smaller storage.</p>
+<p>Loose objects are stored directly on the filesystem, in the Git repository's
+<code>objects</code> directory. Git takes a two-character prefix off of each object's
+SHA-1 hash, and uses that to pick a subdirectory of <code>objects</code> to store the
+object in. The remainder of the hash forms the filename. Loose objects are
+compressed with zlib, to conserve space, but the resulting directory tree can
+still be quite large.</p>
+<p>Packed objects are stored together in packed files, which live in the
+repository's <code>objects/pack</code> directory. These packed files are both compressed
+and delta-encoded, allowing groups of similar objects to be stored very
+compactly.</p>
+ </div>
+
+
+
+<div id="comments">
+<div id="disqus_thread"></div>
+<script type="text/javascript">
+ /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
+ var disqus_shortname = 'grimoire'; // required: replace example with your forum shortname
+
+ /* * * DON'T EDIT BELOW THIS LINE * * */
+ (function() {
+ var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
+ dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+ })();
+</script>
+<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
+<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
+</div>
+
+
+
+ <div id="footer">
+ <p>
+
+ The Codex —
+
+ Powered by <a href="http://markdoc.org/">Markdoc</a>.
+
+<a href="https://bitbucket.org/ojacobson/grimoire.ca/src/master/wiki/git/theory-and-practice/objects.md">See this page on Bitbucket</a> (<a href="https://bitbucket.org/ojacobson/grimoire.ca/history-node/master/wiki/git/theory-and-practice/objects.md">history</a>).
+
+ </p>
+ </div>
+
+</div>
+</body>
+</html> \ No newline at end of file