diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2014-11-29 13:55:47 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2014-11-29 13:55:52 +0100 |
commit | 750e9677b1ce303fa913c3e0754c3884d6517626 (patch) | |
tree | 7e30eccc5046750b4f4fa552e2175113309c6e6b /doc/doc_index/0.1/tutorial.html | |
parent | 8511513540ece43ac8134f3d28380b96db881526 (diff) | |
download | gitpython-750e9677b1ce303fa913c3e0754c3884d6517626.tar.gz |
With docs up on http://gitpython.readthedocs.org, a manually maintained index isn't required anymore
[ci skip]
Diffstat (limited to 'doc/doc_index/0.1/tutorial.html')
-rw-r--r-- | doc/doc_index/0.1/tutorial.html | 352 |
1 files changed, 0 insertions, 352 deletions
diff --git a/doc/doc_index/0.1/tutorial.html b/doc/doc_index/0.1/tutorial.html deleted file mode 100644 index 58725d14..00000000 --- a/doc/doc_index/0.1/tutorial.html +++ /dev/null @@ -1,352 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> - -<html xmlns="http://www.w3.org/1999/xhtml"> - <head> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> - - <title>GitPython Tutorial — GitPython v0.1.7 documentation</title> - <link rel="stylesheet" href="_static/default.css" type="text/css" /> - <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> - <script type="text/javascript"> - var DOCUMENTATION_OPTIONS = { - URL_ROOT: '#', - VERSION: '0.1.7', - COLLAPSE_MODINDEX: false, - FILE_SUFFIX: '.html', - HAS_SOURCE: true - }; - </script> - <script type="text/javascript" src="_static/jquery.js"></script> - <script type="text/javascript" src="_static/doctools.js"></script> - <link rel="top" title="GitPython v0.1.7 documentation" href="index.html" /> - <link rel="next" title="API Reference" href="reference.html" /> - <link rel="prev" title="Overview / Install" href="intro.html" /> - </head> - <body> - <div class="related"> - <h3>Navigation</h3> - <ul> - <li class="right" style="margin-right: 10px"> - <a href="genindex.html" title="General Index" - accesskey="I">index</a></li> - <li class="right" > - <a href="modindex.html" title="Global Module Index" - accesskey="M">modules</a> |</li> - <li class="right" > - <a href="reference.html" title="API Reference" - accesskey="N">next</a> |</li> - <li class="right" > - <a href="intro.html" title="Overview / Install" - accesskey="P">previous</a> |</li> - <li><a href="index.html">GitPython v0.1.7 documentation</a> »</li> - </ul> - </div> - - <div class="document"> - <div class="documentwrapper"> - <div class="bodywrapper"> - <div class="body"> - - <div class="section" id="gitpython-tutorial"> -<span id="tutorial-toplevel"></span><h1>GitPython Tutorial<a class="headerlink" href="#gitpython-tutorial" title="Permalink to this headline">¶</a></h1> -<p>GitPython provides object model access to your git repository. Once you have -created a repository object, you can traverse it to find parent commit(s), -trees, blobs, etc.</p> -<div class="section" id="initialize-a-repo-object"> -<h2>Initialize a Repo object<a class="headerlink" href="#initialize-a-repo-object" title="Permalink to this headline">¶</a></h2> -<p>The first step is to create a <tt class="docutils literal"><span class="pre">Repo</span></tt> object to represent your repository.</p> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">git</span> <span class="kn">import</span> <span class="o">*</span> -<span class="gp">>>> </span><span class="n">repo</span> <span class="o">=</span> <span class="n">Repo</span><span class="p">(</span><span class="s">"/Users/mtrier/Development/git-python"</span><span class="p">)</span> -</pre></div> -</div> -<p>In the above example, the directory <tt class="docutils literal"><span class="pre">/Users/mtrier/Development/git-python</span></tt> -is my working repository and contains the <tt class="docutils literal"><span class="pre">.git</span></tt> directory. You can also -initialize GitPython with a bare repository.</p> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">repo</span> <span class="o">=</span> <span class="n">Repo</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="s">"/var/git/git-python.git"</span><span class="p">)</span> -</pre></div> -</div> -</div> -<div class="section" id="getting-a-list-of-commits"> -<h2>Getting a list of commits<a class="headerlink" href="#getting-a-list-of-commits" title="Permalink to this headline">¶</a></h2> -<p>From the <tt class="docutils literal"><span class="pre">Repo</span></tt> object, you can get a list of <tt class="docutils literal"><span class="pre">Commit</span></tt> -objects.</p> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">repo</span><span class="o">.</span><span class="n">commits</span><span class="p">()</span> -<span class="go">[<git.Commit "207c0c4418115df0d30820ab1a9acd2ea4bf4431">,</span> -<span class="go"> <git.Commit "a91c45eee0b41bf3cdaad3418ca3850664c4a4b4">,</span> -<span class="go"> <git.Commit "e17c7e11aed9e94d2159e549a99b966912ce1091">,</span> -<span class="go"> <git.Commit "bd795df2d0e07d10e0298670005c0e9d9a5ed867">]</span> -</pre></div> -</div> -<p>Called without arguments, <tt class="docutils literal"><span class="pre">Repo.commits</span></tt> returns a list of up to ten commits -reachable by the master branch (starting at the latest commit). You can ask -for commits beginning at a different branch, commit, tag, etc.</p> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">repo</span><span class="o">.</span><span class="n">commits</span><span class="p">(</span><span class="s">'mybranch'</span><span class="p">)</span> -<span class="gp">>>> </span><span class="n">repo</span><span class="o">.</span><span class="n">commits</span><span class="p">(</span><span class="s">'40d3057d09a7a4d61059bca9dca5ae698de58cbe'</span><span class="p">)</span> -<span class="gp">>>> </span><span class="n">repo</span><span class="o">.</span><span class="n">commits</span><span class="p">(</span><span class="s">'v0.1'</span><span class="p">)</span> -</pre></div> -</div> -<p>You can specify the maximum number of commits to return.</p> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">repo</span><span class="o">.</span><span class="n">commits</span><span class="p">(</span><span class="s">'master'</span><span class="p">,</span> <span class="n">max_count</span><span class="o">=</span><span class="mf">100</span><span class="p">)</span> -</pre></div> -</div> -<p>If you need paging, you can specify a number of commits to skip.</p> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">repo</span><span class="o">.</span><span class="n">commits</span><span class="p">(</span><span class="s">'master'</span><span class="p">,</span> <span class="n">max_count</span><span class="o">=</span><span class="mf">10</span><span class="p">,</span> <span class="n">skip</span><span class="o">=</span><span class="mf">20</span><span class="p">)</span> -</pre></div> -</div> -<p>The above will return commits 21-30 from the commit list.</p> -</div> -<div class="section" id="the-commit-object"> -<h2>The Commit object<a class="headerlink" href="#the-commit-object" title="Permalink to this headline">¶</a></h2> -<p>Commit objects contain information about a specific commit.</p> -<blockquote> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">head</span> <span class="o">=</span> <span class="n">repo</span><span class="o">.</span><span class="n">commits</span><span class="p">()[</span><span class="mf">0</span><span class="p">]</span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">head</span><span class="o">.</span><span class="n">id</span> -<span class="go">'207c0c4418115df0d30820ab1a9acd2ea4bf4431'</span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">head</span><span class="o">.</span><span class="n">parents</span> -<span class="go">[<git.Commit "a91c45eee0b41bf3cdaad3418ca3850664c4a4b4">]</span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">head</span><span class="o">.</span><span class="n">tree</span> -<span class="go"><git.Tree "563413aedbeda425d8d9dcbb744247d0c3e8a0ac"></span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">head</span><span class="o">.</span><span class="n">author</span> -<span class="go"><git.Actor "Michael Trier <mtrier@gmail.com>"></span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">head</span><span class="o">.</span><span class="n">authored_date</span> -<span class="go">(2008, 5, 7, 5, 0, 56, 2, 128, 0)</span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">head</span><span class="o">.</span><span class="n">committer</span> -<span class="go"><git.Actor "Michael Trier <mtrier@gmail.com>"></span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">head</span><span class="o">.</span><span class="n">committed_date</span> -<span class="go">(2008, 5, 7, 5, 0, 56, 2, 128, 0)</span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">head</span><span class="o">.</span><span class="n">message</span> -<span class="go">'cleaned up a lot of test information. Fixed escaping so it works with</span> -<span class="go">subprocess.'</span> -</pre></div> -</div> -</blockquote> -<p>Note: date time is represented in a <a class="reference external" href="http://docs.python.org/library/time.html">struct_time</a> format. Conversion to -human readable form can be accomplished with the various time module methods.</p> -<blockquote> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">time</span> -<span class="gp">>>> </span><span class="n">time</span><span class="o">.</span><span class="n">asctime</span><span class="p">(</span><span class="n">head</span><span class="o">.</span><span class="n">committed_date</span><span class="p">)</span> -<span class="go">'Wed May 7 05:56:02 2008'</span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">time</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s">"%a, </span><span class="si">%d</span><span class="s"> %b %Y %H:%M"</span><span class="p">,</span> <span class="n">head</span><span class="o">.</span><span class="n">committed_date</span><span class="p">)</span> -<span class="go">'Wed, 7 May 2008 05:56'</span> -</pre></div> -</div> -</blockquote> -<p>You can traverse a commit’s ancestry by chaining calls to <tt class="docutils literal"><span class="pre">parents</span></tt>.</p> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">repo</span><span class="o">.</span><span class="n">commits</span><span class="p">()[</span><span class="mf">0</span><span class="p">]</span><span class="o">.</span><span class="n">parents</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span><span class="o">.</span><span class="n">parents</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span><span class="o">.</span><span class="n">parents</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span> -</pre></div> -</div> -<p>The above corresponds to <tt class="docutils literal"><span class="pre">master^^^</span></tt> or <tt class="docutils literal"><span class="pre">master~3</span></tt> in git parlance.</p> -</div> -<div class="section" id="the-tree-object"> -<h2>The Tree object<a class="headerlink" href="#the-tree-object" title="Permalink to this headline">¶</a></h2> -<p>A tree records pointers to the contents of a directory. Let’s say you want -the root tree of the latest commit on the master branch.</p> -<blockquote> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">tree</span> <span class="o">=</span> <span class="n">repo</span><span class="o">.</span><span class="n">commits</span><span class="p">()[</span><span class="mf">0</span><span class="p">]</span><span class="o">.</span><span class="n">tree</span> -<span class="go"><git.Tree "a006b5b1a8115185a228b7514cdcd46fed90dc92"></span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">tree</span><span class="o">.</span><span class="n">id</span> -<span class="go">'a006b5b1a8115185a228b7514cdcd46fed90dc92'</span> -</pre></div> -</div> -</blockquote> -<p>Once you have a tree, you can get the contents.</p> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">contents</span> <span class="o">=</span> <span class="n">tree</span><span class="o">.</span><span class="n">values</span><span class="p">()</span> -<span class="go">[<git.Blob "6a91a439ea968bf2f5ce8bb1cd8ddf5bf2cad6c7">,</span> -<span class="go"> <git.Blob "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391">,</span> -<span class="go"> <git.Tree "eaa0090ec96b054e425603480519e7cf587adfc3">,</span> -<span class="go"> <git.Blob "980e72ae16b5378009ba5dfd6772b59fe7ccd2df">]</span> -</pre></div> -</div> -<p>The tree is implements a dictionary protocol so it can be used and acts just -like a dictionary with some additional properties.</p> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">tree</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> -<span class="go">[('lib', <git.Tree "310ebc9a0904531438bdde831fd6a27c6b6be58e">),</span> -<span class="go"> ('LICENSE', <git.Blob "6797c1421052efe2ded9efdbb498b37aeae16415">),</span> -<span class="go"> ('doc', <git.Tree "a58386dd101f6eb7f33499317e5508726dfd5e4f">),</span> -<span class="go"> ('MANIFEST.in', <git.Blob "7da4e346bb0a682e99312c48a1f452796d3fb988">),</span> -<span class="go"> ('.gitignore', <git.Blob "6870991011cc8d9853a7a8a6f02061512c6a8190">),</span> -<span class="go"> ('test', <git.Tree "c6f6ee37d328987bc6fb47a33fed16c7886df857">),</span> -<span class="go"> ('VERSION', <git.Blob "9faa1b7a7339db85692f91ad4b922554624a3ef7">),</span> -<span class="go"> ('AUTHORS', <git.Blob "9f649ef5448f9666d78356a2f66ba07c5fb27229">),</span> -<span class="go"> ('README', <git.Blob "9643dcf549f34fbd09503d4c941a5d04157570fe">),</span> -<span class="go"> ('ez_setup.py', <git.Blob "3031ad0d119bd5010648cf8c038e2bbe21969ecb">),</span> -<span class="go"> ('setup.py', <git.Blob "271074302aee04eb0394a4706c74f0c2eb504746">),</span> -<span class="go"> ('CHANGES', <git.Blob "0d236f3d9f20d5e5db86daefe1e3ba1ce68e3a97">)]</span> -</pre></div> -</div> -<p>This tree contains three <tt class="docutils literal"><span class="pre">Blob</span></tt> objects and one <tt class="docutils literal"><span class="pre">Tree</span></tt> object. The trees -are subdirectories and the blobs are files. Trees below the root have -additional attributes.</p> -<blockquote> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">contents</span> <span class="o">=</span> <span class="n">tree</span><span class="p">[</span><span class="s">"lib"</span><span class="p">]</span> -<span class="go"><git.Tree "c1c7214dde86f76bc3e18806ac1f47c38b2b7a3"></span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">contents</span><span class="o">.</span><span class="n">name</span> -<span class="go">'test'</span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">contents</span><span class="o">.</span><span class="n">mode</span> -<span class="go">'040000'</span> -</pre></div> -</div> -</blockquote> -<p>There is a convenience method that allows you to get a named sub-object -from a tree with a syntax similar to how paths are written in an unix -system.</p> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">tree</span><span class="o">/</span><span class="s">"lib"</span> -<span class="go"><git.Tree "c1c7214dde86f76bc3e18806ac1f47c38b2b7a30"></span> -</pre></div> -</div> -<p>You can also get a tree directly from the repository if you know its name.</p> -<blockquote> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">repo</span><span class="o">.</span><span class="n">tree</span><span class="p">()</span> -<span class="go"><git.Tree "master"></span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">repo</span><span class="o">.</span><span class="n">tree</span><span class="p">(</span><span class="s">"c1c7214dde86f76bc3e18806ac1f47c38b2b7a30"</span><span class="p">)</span> -<span class="go"><git.Tree "c1c7214dde86f76bc3e18806ac1f47c38b2b7a30"></span> -</pre></div> -</div> -</blockquote> -</div> -<div class="section" id="the-blob-object"> -<h2>The Blob object<a class="headerlink" href="#the-blob-object" title="Permalink to this headline">¶</a></h2> -<p>A blob represents a file. Trees often contain blobs.</p> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">blob</span> <span class="o">=</span> <span class="n">tree</span><span class="p">[</span><span class="s">'urls.py'</span><span class="p">]</span> -<span class="go"><git.Blob "b19574431a073333ea09346eafd64e7b1908ef49"></span> -</pre></div> -</div> -<p>A blob has certain attributes.</p> -<blockquote> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">blob</span><span class="o">.</span><span class="n">name</span> -<span class="go">'urls.py'</span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">blob</span><span class="o">.</span><span class="n">mode</span> -<span class="go">'100644'</span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">blob</span><span class="o">.</span><span class="n">mime_type</span> -<span class="go">'text/x-python'</span> -</pre></div> -</div> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">blob</span><span class="o">.</span><span class="n">size</span> -<span class="go">415</span> -</pre></div> -</div> -</blockquote> -<p>You can get the data of a blob as a string.</p> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">blob</span><span class="o">.</span><span class="n">data</span> -<span class="go">"from django.conf.urls.defaults import *\nfrom django.conf..."</span> -</pre></div> -</div> -<p>You can also get a blob directly from the repo if you know its name.</p> -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">repo</span><span class="o">.</span><span class="n">blob</span><span class="p">(</span><span class="s">"b19574431a073333ea09346eafd64e7b1908ef49"</span><span class="p">)</span> -<span class="go"><git.Blob "b19574431a073333ea09346eafd64e7b1908ef49"></span> -</pre></div> -</div> -</div> -<div class="section" id="what-else"> -<h2>What Else?<a class="headerlink" href="#what-else" title="Permalink to this headline">¶</a></h2> -<p>There is more stuff in there, like the ability to tar or gzip repos, stats, -log, blame, and probably a few other things. Additionally calls to the git -instance are handled through a <tt class="docutils literal"><span class="pre">__getattr__</span></tt> construct, which makes -available any git commands directly, with a nice conversion of Python dicts -to command line parameters.</p> -<p>Check the unit tests, they’re pretty exhaustive.</p> -</div> -</div> - - - </div> - </div> - </div> - <div class="sphinxsidebar"> - <div class="sphinxsidebarwrapper"> - <h3><a href="index.html">Table Of Contents</a></h3> - <ul> -<li><a class="reference external" href="#">GitPython Tutorial</a><ul> -<li><a class="reference external" href="#initialize-a-repo-object">Initialize a Repo object</a></li> -<li><a class="reference external" href="#getting-a-list-of-commits">Getting a list of commits</a></li> -<li><a class="reference external" href="#the-commit-object">The Commit object</a></li> -<li><a class="reference external" href="#the-tree-object">The Tree object</a></li> -<li><a class="reference external" href="#the-blob-object">The Blob object</a></li> -<li><a class="reference external" href="#what-else">What Else?</a></li> -</ul> -</li> -</ul> - - <h4>Previous topic</h4> - <p class="topless"><a href="intro.html" - title="previous chapter">Overview / Install</a></p> - <h4>Next topic</h4> - <p class="topless"><a href="reference.html" - title="next chapter">API Reference</a></p> - <h3>This Page</h3> - <ul class="this-page-menu"> - <li><a href="_sources/tutorial.txt" - rel="nofollow">Show Source</a></li> - </ul> - <div id="searchbox" style="display: none"> - <h3>Quick search</h3> - <form class="search" action="search.html" method="get"> - <input type="text" name="q" size="18" /> - <input type="submit" value="Go" /> - <input type="hidden" name="check_keywords" value="yes" /> - <input type="hidden" name="area" value="default" /> - </form> - <p class="searchtip" style="font-size: 90%"> - Enter search terms or a module, class or function name. - </p> - </div> - <script type="text/javascript">$('#searchbox').show(0);</script> - </div> - </div> - <div class="clearer"></div> - </div> - <div class="related"> - <h3>Navigation</h3> - <ul> - <li class="right" style="margin-right: 10px"> - <a href="genindex.html" title="General Index" - >index</a></li> - <li class="right" > - <a href="modindex.html" title="Global Module Index" - >modules</a> |</li> - <li class="right" > - <a href="reference.html" title="API Reference" - >next</a> |</li> - <li class="right" > - <a href="intro.html" title="Overview / Install" - >previous</a> |</li> - <li><a href="index.html">GitPython v0.1.7 documentation</a> »</li> - </ul> - </div> - <div class="footer"> - © Copyright Copyright (C) 2008-2010 Michael Trier and contributors. - Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.5. - </div> - </body> -</html>
\ No newline at end of file |