@@ -54,7 +54,7 @@ the history of your project.
54
54
>>> heads = repo.heads
55
55
>>> master = heads.master # lists can be accessed by name for convenience
56
56
>>> master.commit # the commit pointed to by head called master
57
- >>> master.rename(" new_name" ) # rename individual heads or
57
+ >>> master.rename(" new_name" ) # rename heads
58
58
59
59
Tags are (usually immutable) references to a commit and/or a tag object.
60
60
@@ -63,18 +63,22 @@ Tags are (usually immutable) references to a commit and/or a tag object.
63
63
>>> tagref.tag # tags may have tag objects carrying additional information
64
64
>>> tagref.commit # but they always point to commits
65
65
>>> repo.delete_tag(tagref) # delete or
66
- >>> repo.create_tag(" my_tag" ) # create tags using the repo
66
+ >>> repo.create_tag(" my_tag" ) # create tags using the repo for convenience
67
67
68
68
A symbolic reference is a special case of a reference as it points to another
69
69
reference instead of a commit
70
70
71
+ >>> head = repo.head # the head points to the active branch/ref
72
+ >>> master = head.reference # retrieve the reference the head points to
73
+ >>> master.commit # from here you use it as any other reference
74
+
71
75
Modifying References
72
76
********************
73
77
You can easily create and delete reference types or modify where they point to.
74
78
75
- >>> repo.delete_head(' master' )
76
- >>> master = repo.create_head(' master' )
77
- >>> master.commit = ' HEAD~10' # set another commit without changing index or working tree
79
+ >>> repo.delete_head(' master' ) # delete an existing head
80
+ >>> master = repo.create_head(' master' ) # create a new one
81
+ >>> master.commit = ' HEAD~10' # set branch to another commit without changing index or working tree
78
82
79
83
Create or delete tags the same way except you may not change them afterwards
80
84
@@ -89,9 +93,10 @@ or the working copy )
89
93
90
94
Understanding Objects
91
95
*********************
92
- An Object is anything storable in gits object database. Objects contain information
93
- about their type, their uncompressed size as well as their data. Each object is
94
- uniquely identified by a SHA1 hash, being 40 hexadecimal characters in size.
96
+ An Object is anything storable in git's object database. Objects contain information
97
+ about their type, their uncompressed size as well as the actual data. Each object is
98
+ uniquely identified by a SHA1 hash, being 40 hexadecimal characters in size or 20
99
+ bytes in size.
95
100
96
101
Git only knows 4 distinct object types being Blobs, Trees, Commits and Tags.
97
102
@@ -116,7 +121,7 @@ Basic fields are
116
121
'...'
117
122
>>> len (hct.data) == hct.size
118
123
119
- Index Objects are objects that can be put into gits index. These objects are trees
124
+ Index Objects are objects that can be put into git's index. These objects are trees
120
125
and blobs which additionally know about their path in the filesystem as well as their
121
126
mode.
122
127
@@ -130,8 +135,8 @@ mode.
130
135
100644
131
136
132
137
Access blob data (or any object data) directly or using streams.
133
- >>> htc.data # binary tree data
134
- >>> htc.blobs[0 ].data_stream # stream object to read data from
138
+ >>> htc.data # binary tree data as string ( inefficient )
139
+ >>> htc.blobs[0 ].data_stream # stream object to read data from
135
140
>>> htc.blobs[0 ].stream_data(my_stream) # write data to given stream
136
141
137
142
@@ -157,7 +162,7 @@ If you need paging, you can specify a number of commits to skip.
157
162
158
163
The above will return commits 21-30 from the commit list.
159
164
160
- >>> headcommit = repo.headcommit .commit
165
+ >>> headcommit = repo.head .commit
161
166
162
167
>>> headcommit.sha
163
168
'207c0c4418115df0d30820ab1a9acd2ea4bf4431'
@@ -228,9 +233,9 @@ Once you have a tree, you can get the contents.
228
233
Its useful to know that a tree behaves like a list with the ability to
229
234
query entries by name.
230
235
231
- >>> tree[0 ] == tree[' dir' ]
236
+ >>> tree[0 ] == tree[' dir' ] # access by index and by sub-path
232
237
<git.Tree "f7eb5df2e465ab621b1db3f5714850d6732cfed2">
233
- >>> for entry in tree: do_something (entry)
238
+ >>> for entry in tree: do_something_with (entry)
234
239
235
240
>>> blob = tree[0 ][0 ]
236
241
>>> blob.name
@@ -260,18 +265,18 @@ You can also get a tree directly from the repository if you know its name.
260
265
<git.Tree "6825a94104164d9f0f5632607bebd2a32a3579e5">
261
266
262
267
As trees only allow direct access to their direct entries, use the traverse
263
- method to obtain an iterator to access entries recursively.
268
+ method to obtain an iterator to traverse entries recursively.
264
269
265
270
>>> tree.traverse()
266
271
<generator object at 0x7f6598bd65a8>
267
- >>> for entry in traverse(): do_something (entry)
272
+ >>> for entry in traverse(): do_something_with (entry)
268
273
269
274
270
275
The Index Object
271
276
****************
272
- The git index is the stage containing changes to be written to the next commit
277
+ The git index is the stage containing changes to be written with the next commit
273
278
or where merges finally have to take place. You may freely access and manipulate
274
- this information using the Index Object.
279
+ this information using the IndexFile Object.
275
280
276
281
>>> index = repo.index
277
282
@@ -289,7 +294,7 @@ Create new indices from other trees or as result of a merge. Write that result t
289
294
a new index.
290
295
291
296
>>> tmp_index = Index.from_tree(repo, ' HEAD~1' ) # load a tree into a temporary index
292
- >>> merge_index = Index.from_tree(repo, ' HEAD' , ' some_branch' ) # merge two trees
297
+ >>> merge_index = Index.from_tree(repo, ' base ' , ' HEAD' , ' some_branch' ) # merge two trees three-way
293
298
>>> merge_index.write(" merged_index" )
294
299
295
300
Handling Remotes
@@ -314,7 +319,7 @@ as if they where attributes.
314
319
'git@server:dummy_repo.git'
315
320
316
321
Change configuration for a specific remote only
317
- >>> o.config_writer.set(" url " , " other_url" )
322
+ >>> o.config_writer.set(" pushurl " , " other_url" )
318
323
319
324
Obtaining Diff Information
320
325
**************************
@@ -323,7 +328,7 @@ Diffs can generally be obtained by Subclasses of ``Diffable`` as they provide
323
328
the ``diff `` method. This operation yields a DiffIndex allowing you to easily access
324
329
diff information about paths.
325
330
326
- Diffs can be made between Index and Trees, Index and the working tree, trees and
331
+ Diffs can be made between the Index and Trees, Index and the working tree, trees and
327
332
trees as well as trees and the working copy. If commits are involved, their tree
328
333
will be used implicitly.
329
334
@@ -338,9 +343,9 @@ will be used implicitly.
338
343
>>> index.diff(' HEAD' ) # diff index against current HEAD tree
339
344
340
345
The item returned is a DiffIndex which is essentially a list of Diff objects. It
341
- provides additional filtering to find what you might be looking for
346
+ provides additional filtering to ease finding what you might be looking for.
342
347
343
- >>> for diff_added in wdiff.iter_change_type(' A' ): do_something (diff_added)
348
+ >>> for diff_added in wdiff.iter_change_type(' A' ): do_something_with (diff_added)
344
349
345
350
Switching Branches
346
351
******************
@@ -349,7 +354,7 @@ head and reset your index and working copy to match. A simple manual way to do i
349
354
is the following one.
350
355
351
356
>>> repo.head.reference = repo.heads.other_branch
352
- >>> repo.head.reset(index = True , working_tree = True
357
+ >>> repo.head.reset(index = True , working_tree = True )
353
358
354
359
The previous approach would brutally overwrite the user's changes in the working copy
355
360
and index though and is less sophisticated than a git-checkout for instance which
0 commit comments