got log and cat-file moved to pure ruby
[rubygit.git] / doc / files / EXAMPLES.html
blob63163ef867c4726f6f840fea886f1decd3500ba0
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>Mon Nov 12 10:27:43 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 Here are a bunch of examples of how to use the Ruby/<a
74 href="../classes/Git.html">Git</a> package.
75 </p>
76 <p>
77 First you have to remember to require rubygems if it&#8217;s not. Then
78 include the &#8216;git&#8217; gem.
79 </p>
80 <pre>
81 require 'rubygems'
82 gem 'git'
83 </pre>
84 <p>
85 Here are the operations that need read permission only.
86 </p>
87 <pre>
88 g = Git.open (working_dir = '.')
89 (git_dir, index_file)
91 g.index
92 g.index.readable?
93 g.index.writable?
94 g.repo
95 g.dir
97 g.log # returns array of Git::Commit objects
98 g.log.since('2 weeks ago')
99 g.log.between('v2.5', 'v2.6')
100 g.log.each {|l| puts l.sha }
101 g.gblob('v2.5:Makefile').log.since('2 weeks ago')
103 g.object('HEAD^').to_s # git show / git rev-parse
104 g.object('HEAD^').contents
105 g.object('v2.5:Makefile').size
106 g.object('v2.5:Makefile').sha
108 g.gtree(treeish)
109 g.gblob(treeish)
110 g.gcommit(treeish)
112 g.revparse('v2.5:Makefile')
114 g.branches # returns Git::Branch objects
115 g.branches.local
116 g.branches.remote
117 g.branches[:master].gcommit
118 g.branches['origin/master'].gcommit
120 g.grep('hello') # implies HEAD
121 g.blob('v2.5:Makefile').grep('hello')
122 g.tag('v2.5').grep('hello', 'docs/')
124 g.diff(commit1, commit2).size
125 g.diff(commit1, commit2).stats
126 g.gtree('v2.5').diff('v2.6').insertions
127 g.diff('gitsearch1', 'v2.5').path('lib/')
128 g.diff('gitsearch1', @git.gtree('v2.5'))
129 g.diff('gitsearch1', 'v2.5').path('docs/').patch
130 g.gtree('v2.5').diff('v2.6').patch
132 g.gtree('v2.5').diff('v2.6').each do |file_diff|
133 puts file_diff.path
134 puts file_diff.patch
135 puts file_diff.blob(:src).contents
138 g.config('user.name') # returns 'Scott Chacon'
139 g.config # returns whole config hash
141 g.tag # returns array of Git::Tag objects
142 </pre>
144 And here are the operations that will need to write to your git repository.
145 </p>
146 <pre>
147 g = Git.init
148 Git.init('project')
149 Git.init('/home/schacon/proj',
150 { :git_dir =&gt; '/opt/git/proj.git',
151 :index_file =&gt; '/tmp/index'} )
153 g = Git.clone(URI, :name =&gt; 'name', :path =&gt; '/tmp/checkout'
154 (git_dir, index_file)
156 g.config('user.name', 'Scott Chacon')
157 g.config('user.email', 'email@email.com')
159 g.add('.')
160 g.add([file1, file2])
162 g.remove('file.txt')
163 g.remove(['file.txt', 'file2.txt'])
165 g.commit('message')
166 g.commit_all('message')
168 g = Git.clone(repo, 'myrepo')
169 Dir.chdir('myrepo') do
170 new_file('test-file', 'blahblahblah')
171 g.status.changed.each do |file|
172 puts file.blob(:index).contents
176 g.reset # defaults to HEAD
177 g.reset_hard(Git::Commit)
179 g.branch('new_branch') # creates new or fetches existing
180 g.branch('new_branch').checkout
181 g.branch('new_branch').delete
182 g.branch('existing_branch').checkout
184 g.checkout('new_branch')
185 g.checkout(g.branch('new_branch'))
187 g.branch(name).merge(branch2)
188 g.branch(branch2).merge # merges HEAD with branch2
190 g.branch(name).in_branch(message) { # add files } # auto-commits
191 g.merge('new_branch')
192 g.merge('origin/remote_branch')
193 g.merge(b.branch('master'))
194 g.merge([branch1, branch2])
196 r = g.add_remote(name, uri) # Git::Remote
197 r = g.add_remote(name, Git::Base) # Git::Remote
199 g.remotes # array of Git::Remotes
200 g.remote(name).fetch
201 g.remote(name).remove
202 g.remote(name).merge
203 g.remote(name).merge(branch)
205 g.fetch
206 g.fetch(g.remotes.first)
208 g.pull
209 g.pull(Git::Repo, Git::Branch) # fetch and a merge
211 g.add_tag('tag_name') # returns Git::Tag
213 g.repack
214 </pre>
216 </div>
219 </div>
222 </div>
225 <!-- if includes -->
227 <div id="section">
236 <!-- if method_list -->
239 </div>
242 <div id="validator-badges">
243 <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
244 </div>
246 </body>
247 </html>