added branches, more log stuff, better tests, changed the log api a bit
[rubygit.git] / EXAMPLES
blobbea9be7927c68f6e24c082bbefb3b5e34bbcdde2
1 require 'git'
3 # needs read permission only
5 g = Git.open (working_dir = '.')
6         (git_dir, index_file)
8 g.index
9 g.index.readable?
10 g.index.writable?
11 g.repo
12 g.dir
14 g.log   # returns array of Git::Commit objects
15 g.log.since('2 weeks ago')
16 g.log.between('v2.5', 'v2.6')
17 g.log.each {|l| puts l.sha }
18 g.blob('v2.5:Makefile').log.since('2 weeks ago')
20 g.object('HEAD^').to_s  # git show / git rev-parse
21 g.object('HEAD^').contents
22 g.object('v2.5:Makefile').size
23 g.object('v2.5:Makefile').sha
25 g.tree(treeish)
26 g.blob(treeish)
27 g.commit(treeish)
29 g.revparse('v2.5:Makefile')
31 g.branches # returns Git::Branch objects
32 g.branches.local
33 g.branches.remote
34 g.branches[:master].commit
35 g.branches['origin/master'].commit
37 g.grep('hello')  # implies HEAD
38 g.blob('v2.5:Makefile').grep('hello')
39 g.tag('v2.5').grep('hello', 'docs/')
42 ***** IMPLEMENTED *****
44 g.diff
45 g.diff.shortstat
46 g.diff.summary
47 g.diff(commit1, commit2)
48 g.diff("commit1..commit2")
50 g.diff_tree(Git::Tree, Git::Tree)
53 g.status
55 g.ls_files
56 g.ls_files(:stage => true)
58 g.tag # returns array of Git::Tag objects
61 # needs write permission
63 g = Git.clone(URI, 'name', working_dir = GIT_DIR, {options})
64         (username, password, ssl_key, git_dir, index_file)
66 g = Git.init
67   Git.init('project')
68   Git.init('/home/schacon/proj', 
69                 { :git_dir => '/opt/git/proj.git', 
70                   :index_file => '/tmp/index'} )
74 g.config('user.name', 'Scott Chacon')
75 g.config('user.email', 'email@email.com')
76 g.config('user.name')  # returns 'Scott Chacon'
77 g.config # returns whole config hash
79 g.add('.')
80 g.add([file1, file2])
82 g.remove('file.txt').and_file
84 g.commit('message')
85 g.commit_a('message')
87 g.reset # defaults to HEAD
88 g.reset_hard(Git::Commit)
90 g.branch('new_branch')
91 g.branch('new_branch').delete
93 g.checkout('new_branch')
94 g.checkout('new_branch', :create_branch => true)
95 g.checkout_b('new_branch')
97 g.merge('new_branch')
98 g.merge(Git::Branch)
99 g.merge(Git::Branch, Git::Branch)
101 g.fetch
102 g.fetch(Git::Repo)
104 g.pull
105 g.pull(Git::Repo, Git::Branch) # fetch and a merge
107 g.tag('tag_name') # returns Git::Tag
109 g.pack