added documentation and a license file
[rubygit.git] / doc / files / EXAMPLES.html
blobef92243052f1dd85f5b4bc511b9b78344dc39c52
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <!DOCTYPE html
3 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7 <head>
8 <title>File: EXAMPLES</title>
9 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10 <meta http-equiv="Content-Script-Type" content="text/javascript" />
11 <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12 <script type="text/javascript">
13 // <![CDATA[
15 function popupCode( url ) {
16 window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
19 function toggleCode( id ) {
20 if ( document.getElementById )
21 elem = document.getElementById( id );
22 else if ( document.all )
23 elem = eval( "document.all." + id );
24 else
25 return false;
27 elemStyle = elem.style;
29 if ( elemStyle.display != "block" ) {
30 elemStyle.display = "block"
31 } else {
32 elemStyle.display = "none"
35 return true;
38 // Make codeblocks hidden by default
39 document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
41 // ]]>
42 </script>
44 </head>
45 <body>
49 <div id="fileHeader">
50 <h1>EXAMPLES</h1>
51 <table class="header-table">
52 <tr class="top-aligned-row">
53 <td><strong>Path:</strong></td>
54 <td>EXAMPLES
55 </td>
56 </tr>
57 <tr class="top-aligned-row">
58 <td><strong>Last Update:</strong></td>
59 <td>Sun Nov 11 17:51:57 PST 2007</td>
60 </tr>
61 </table>
62 </div>
63 <!-- banner header -->
65 <div id="bodyContent">
69 <div id="contextContent">
71 <div id="description">
72 <p>
73 require &#8216;git&#8217;
74 </p>
75 <p>
76 # needs read permission only
77 </p>
78 <p>
79 g = <a href="../classes/Git.html#M000002">Git.open</a> (working_dir =
80 &#8217;.&#8217;)
81 </p>
82 <pre>
83 (git_dir, index_file)
84 </pre>
85 <p>
86 g.index g.index.readable? g.index.writable? g.repo g.dir
87 </p>
88 <p>
89 g.log # returns array of Git::Commit objects g.log.since(&#8216;2 weeks
90 ago&#8217;) g.log.between(&#8216;v2.5&#8217;, &#8216;v2.6&#8217;)
91 g.log.each {|l| puts l.sha }
92 g.gblob(&#8216;v2.5:Makefile&#8217;).log.since(&#8216;2 weeks ago&#8217;)
93 </p>
94 <p>
95 g.object(&#8216;HEAD^&#8217;).to_s # git show / git rev-parse
96 g.object(&#8216;HEAD^&#8217;).contents
97 g.object(&#8216;v2.5:Makefile&#8217;).size
98 g.object(&#8216;v2.5:Makefile&#8217;).sha
99 </p>
101 g.gtree(treeish) g.gblob(treeish) g.gcommit(treeish)
102 </p>
104 g.revparse(&#8216;v2.5:Makefile&#8217;)
105 </p>
107 g.branches # returns <a href="../classes/Git/Branch.html">Git::Branch</a>
108 objects g.branches.local g.branches.remote g.branches[:master].gcommit
109 g.branches[&#8216;origin/master&#8217;].gcommit
110 </p>
112 g.grep(&#8216;hello&#8217;) # implies HEAD
113 g.blob(&#8216;v2.5:Makefile&#8217;).grep(&#8216;hello&#8217;)
114 g.tag(&#8216;v2.5&#8217;).grep(&#8216;hello&#8217;, &#8216;docs/&#8217;)
115 </p>
117 g.diff(commit1, commit2).size g.diff(commit1, commit2).stats
118 g.gtree(&#8216;v2.5&#8217;).diff(&#8216;v2.6&#8217;).insertions
119 g.diff(&#8216;gitsearch1&#8217;,
120 &#8216;v2.5&#8217;).path(&#8216;lib/&#8217;)
121 g.diff(&#8216;gitsearch1&#8217;, @git.gtree(&#8216;v2.5&#8217;))
122 g.diff(&#8216;gitsearch1&#8217;,
123 &#8216;v2.5&#8217;).path(&#8216;docs/&#8217;).patch
124 g.gtree(&#8216;v2.5&#8217;).diff(&#8216;v2.6&#8217;).patch
125 </p>
127 g.gtree(&#8216;v2.5&#8217;).diff(&#8216;v2.6&#8217;).each do |file_diff|
128 </p>
129 <pre>
130 puts file_diff.path
131 puts file_diff.patch
132 puts file_diff.blob(:src).contents
133 </pre>
136 </p>
138 g.config(&#8216;user.name&#8217;) # returns &#8216;Scott Chacon&#8217;
139 g.config # returns whole config hash
140 </p>
142 g.tag # returns array of Git::Tag objects
143 </p>
145 # needs write permission
146 </p>
148 g = <a href="../classes/Git.html#M000003">Git.init</a>
149 </p>
150 <pre>
151 Git.init('project')
152 Git.init('/home/schacon/proj',
153 { :git_dir =&gt; '/opt/git/proj.git',
154 :index_file =&gt; '/tmp/index'} )
155 </pre>
157 g = <a href="../classes/Git.html#M000004">Git.clone</a>(URI, :name =&gt;
158 &#8216;name&#8217;, :path =&gt; &#8217;/tmp/checkout&#8216;
159 </p>
160 <pre>
161 (git_dir, index_file)
162 </pre>
164 g.config(&#8216;user.name&#8217;, &#8216;Scott Chacon&#8217;)
165 g.config(&#8216;user.email&#8217;, &#8216;email@email.com&#8217;)
166 </p>
168 g.add(&#8217;.&#8217;) g.add([file1, file2])
169 </p>
171 g.remove(&#8216;file.txt&#8217;) g.remove([&#8216;file.txt&#8217;,
172 &#8216;file2.txt&#8217;])
173 </p>
175 g.commit(&#8216;message&#8217;) g.commit_all(&#8216;message&#8217;)
176 </p>
178 g = <a href="../classes/Git.html#M000004">Git.clone</a>(repo,
179 &#8216;myrepo&#8217;) Dir.chdir(&#8216;myrepo&#8217;) do
180 </p>
181 <pre>
182 new_file('test-file', 'blahblahblah')
183 g.status.untracked.each do |file|
184 puts file.blob(:index).contents
186 </pre>
189 </p>
191 g.reset # defaults to HEAD g.reset_hard(Git::Commit)
192 </p>
194 g.branch(&#8216;new_branch&#8217;) # creates new or fetches existing
195 g.branch(&#8216;new_branch&#8217;).checkout
196 g.branch(&#8216;new_branch&#8217;).delete
197 g.branch(&#8216;existing_branch&#8217;).checkout
198 </p>
200 g.checkout(&#8216;new_branch&#8217;)
201 g.checkout(g.branch(&#8216;new_branch&#8217;))
202 </p>
204 g.branch(name).merge(branch2) g.branch(branch2).merge # merges HEAD with
205 branch2
206 </p>
208 g.branch(name).in_branch(message) { # add files } # auto-commits
209 g.merge(&#8216;new_branch&#8217;)
210 g.merge(&#8216;origin/remote_branch&#8217;)
211 g.merge(b.branch(&#8216;master&#8217;)) g.merge([branch1, branch2])
212 </p>
214 r = g.add_remote(name, uri) # <a
215 href="../classes/Git/Remote.html">Git::Remote</a> r = g.add_remote(name, <a
216 href="../classes/Git/Base.html">Git::Base</a>) # <a
217 href="../classes/Git/Remote.html">Git::Remote</a>
218 </p>
220 g.remotes # array of Git::Remotes g.remote(name).fetch
221 g.remote(name).remove g.remote(name).merge g.remote(name).merge(branch)
222 </p>
224 g.fetch g.fetch(g.remotes.first)
225 </p>
227 g.pull g.pull(Git::Repo, <a
228 href="../classes/Git/Branch.html">Git::Branch</a>) # fetch and a merge
229 </p>
231 g.add_tag(&#8216;tag_name&#8217;) # returns Git::Tag
232 </p>
234 g.repack
235 </p>
237 </div>
240 </div>
243 </div>
246 <!-- if includes -->
248 <div id="section">
257 <!-- if method_list -->
260 </div>
263 <div id="validator-badges">
264 <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
265 </div>
267 </body>
268 </html>