summaryrefslogtreecommitdiffstats
path: root/README
blob: dacfefead0d6bdb855e19faff7290fb57e3db126 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
Git Library for Ruby
-----------------------------

Git
Git::Repository
Git::Index 
Git::WorkingDirectory << Dir

Git::Object 

Git::Commit << Git::Object
Git::Blob
Git::Tree
Git::Tag

Git::Author
Git::Ref 
Git::File (in working dir)
Git::Log
Git::Sha
Git::Diff
Git::Branch 
Git::Remote << Git::Repository

require 'git'


# needs read permission only

g = Git.open (working_dir = '.')
	(git_dir, index_file)

g.index
g.index.readable?
g.index.writable?
g.repo
g.dir

g.log   # returns array of Git::Commit objects
g.log.since('2 weeks ago')
g.log.between('v2.5', 'v2.6')
g.log.since('v2.5').file('Makefile')
g.log.each {|l| puts l.sha }

g.object('HEAD^').to_s  # git show / git rev-parse
g.object('HEAD^').contents
g.object('v2.5:Makefile').size
g.object('v2.5:Makefile').sha

g.revparse('v2.5:Makefile')

**********

g.file('flim/ChangeLog').tags.each {|tag,rev| p [tag,rev.to_s]}
g.file('flim/ChangeLog').logs.each { |log| log.sha }

g.branches # returns Git::Branch objects
g.branches.local
g.branches.remote

g.status

g.grep('hello')
g.grep('hello', Git::Tag)


g.ls_files
g.ls_files(:stage => true)

g.diff
g.diff_cached
g.diff(commit1, commit2)
g.diff("commit1..commit2")

g.diff_tree(Git::Tree, Git::Tree)

g.tag # returns array of Git::Tag objects


# needs write permission

g = Git.clone(URI, 'name', working_dir = GIT_DIR, {options})
	(username, password, ssl_key, git_dir, index_file)

g = Git.init
  Git.init('project')
  Git.init('/home/schacon/proj', 
		{ :git_dir => '/opt/git/proj.git', 
		  :index_file => '/tmp/index'} )



g.config('user.name', 'Scott Chacon')
g.config('user.email', 'email@email.com')
g.config('user.name')  # returns 'Scott Chacon'
g.config # returns whole config hash

g.add('.')
g.add([file1, file2])

g.remove('file.txt').and_file

g.commit('message')
g.commit_a('message')

g.reset # defaults to HEAD
g.reset_hard(Git::Commit)

g.branch('new_branch')
g.branch('new_branch').delete

g.checkout('new_branch')
g.checkout('new_branch', :create_branch => true)
g.checkout_b('new_branch')

g.merge('new_branch')
g.merge(Git::Branch)
g.merge(Git::Branch, Git::Branch)

g.fetch
g.fetch(Git::Repo)

g.pull
g.pull(Git::Repo, Git::Branch) # fetch and a merge

g.tag('tag_name') # returns Git::Tag

g.pack



Git::Object
  - sha
  - type
  - cat_file
  - raw

Git::Commit
  - tree
  - parent 
  - author      # git author
  - author_date
  - committer   # git author
  - committer_date / date
  - message

Git::Tree
  - children
  - blobs/files
  - subtrees/subdirs

Git::Blob << File
  - size
  - permissions

Git::Tag

Git::Hash
  - abbrev/short

Git::Repository
  - heads
  - refs
  - branches

Git::WorkingDirectory 
  - foreach
  - glob # returns Git::Files

Git::File << File
  - log
  - tags