@@ -31,8 +31,6 @@ the history of your project.
3131 >>> master = heads.master # lists can be accessed by name for convenience
3232 >>> master.commit # the commit pointed to by head called master
3333 >>> master.rename(" new_name" ) # rename individual heads or
34- >>> repo.delete_head(master) # delete them or
35- >>> repo.create_head(' master' ) # create them
3634
3735Tags are (usually immutable) references to a commit and/or a tag object.
3836
@@ -42,6 +40,28 @@ Tags are (usually immutable) references to a commit and/or a tag object.
4240 >>> tagref.commit # but they always point to commits
4341 >>> repo.delete_tag(tagref) # delete or
4442 >>> repo.create_tag(" my_tag" ) # create tags using the repo
43+
44+ A symbolic reference is a special case of a reference as it points to another
45+ reference instead of a commit
46+
47+ Modifying References
48+ ********************
49+ You can easily create and delete reference types or modify where they point to.
50+
51+ >>> repo.delete_head(' master' )
52+ >>> master = repo.create_head(' master' )
53+ >>> master.commit = ' HEAD~10' # set another commit without changing index or working tree
54+
55+ Create or delete tags the same way except you may not change them afterwards
56+
57+ >>> new_tag = repo.create_tag(' my_tag' , ' my message' )
58+ >>> repo.delete_tag(new_tag)
59+
60+ Change the symbolic reference to switch branches cheaply ( without adjusting the index
61+ or the working copy )
62+
63+ >>> new_branch = repo.create_head(' new_branch' )
64+ >>> repo.head.reference = new_branch
4565
4666Understanding Objects
4767*********************
@@ -54,12 +74,43 @@ Git only knows 4 distinct object types being Blobs, Trees, Commits and Tags.
5474In Git-Pyhton, all objects can be accessed through their common base, compared
5575and hashed, as shown in the following example.
5676
57- >>>
77+ >>> hc = repo.head.commit
78+ >>> hct = hc.tree
79+ >>> hc != hct
80+ >>> hc != repo.tags[0 ]
81+ >>> hc == repo.head.reference.commit
82+
83+ Basic fields are
84+
85+ >>> hct.type
86+ 'tree'
87+ >>> hct.size
88+ 166
89+ >>> hct.sha
90+ 'a95eeb2a7082212c197cabbf2539185ec74ed0e8'
91+ >>> hct.data # returns string with pure uncompressed data
92+ '...'
93+ >>> len (hct.data) == hct.size
5894
5995Index Objects are objects that can be put into gits index. These objects are trees
6096and blobs which additionally know about their path in the filesystem as well as their
6197mode.
6298
99+ >>> hct.path # root tree has no path
100+ ''
101+ >>> hct.trees[0 ].path # the first subdirectory has one though
102+ 'dir'
103+ >>> htc.mode # trees have mode 0
104+ 0
105+ >>> ' %o ' % htc.blobs[0 ].mode # blobs have a specific mode though comparable to a standard linux fs
106+ 100644
107+
108+ Access blob data (or any object data) directly or using streams.
109+ >>> htc.data # binary tree data
110+ >>> htc.blobs[0 ].data_stream # stream object to read data from
111+ >>> htc.blobs[0 ].stream_data(my_stream) # write data to given stream
112+
113+
63114The Commit object
64115*****************
65116
@@ -133,43 +184,29 @@ The Tree object
133184A tree records pointers to the contents of a directory. Let's say you want
134185the root tree of the latest commit on the master branch.
135186
136- >>> tree = repo.commits()[ 0 ] .tree
187+ >>> tree = repo.heads.master.commit .tree
137188 <git.Tree "a006b5b1a8115185a228b7514cdcd46fed90dc92">
138189
139- >>> tree.id
190+ >>> tree.sha
140191 'a006b5b1a8115185a228b7514cdcd46fed90dc92'
141192
142193Once you have a tree, you can get the contents.
143194
144- >>> contents = tree.values()
145- [<git.Blob "6a91a439ea968bf2f5ce8bb1cd8ddf5bf2cad6c7">,
146- <git.Blob "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391">,
147- <git.Tree "eaa0090ec96b054e425603480519e7cf587adfc3">,
148- <git.Blob "980e72ae16b5378009ba5dfd6772b59fe7ccd2df">]
149-
150- The tree is implements a dictionary protocol so it can be used and acts just
151- like a dictionary with some additional properties.
152-
153- >>> tree.items()
154- [('lib', <git.Tree "310ebc9a0904531438bdde831fd6a27c6b6be58e">),
155- ('LICENSE', <git.Blob "6797c1421052efe2ded9efdbb498b37aeae16415">),
156- ('doc', <git.Tree "a58386dd101f6eb7f33499317e5508726dfd5e4f">),
157- ('MANIFEST.in', <git.Blob "7da4e346bb0a682e99312c48a1f452796d3fb988">),
158- ('.gitignore', <git.Blob "6870991011cc8d9853a7a8a6f02061512c6a8190">),
159- ('test', <git.Tree "c6f6ee37d328987bc6fb47a33fed16c7886df857">),
160- ('VERSION', <git.Blob "9faa1b7a7339db85692f91ad4b922554624a3ef7">),
161- ('AUTHORS', <git.Blob "9f649ef5448f9666d78356a2f66ba07c5fb27229">),
162- ('README', <git.Blob "9643dcf549f34fbd09503d4c941a5d04157570fe">),
163- ('ez_setup.py', <git.Blob "3031ad0d119bd5010648cf8c038e2bbe21969ecb">),
164- ('setup.py', <git.Blob "271074302aee04eb0394a4706c74f0c2eb504746">),
165- ('CHANGES', <git.Blob "0d236f3d9f20d5e5db86daefe1e3ba1ce68e3a97">)]
166-
167- This tree contains three ``Blob `` objects and one ``Tree `` object. The trees
168- are subdirectories and the blobs are files. Trees below the root have
169- additional attributes.
170-
171- >>> contents = tree[" lib" ]
172- <git.Tree "c1c7214dde86f76bc3e18806ac1f47c38b2b7a3">
195+ >>> tree.trees # trees are subdirectories
196+ [<git.Tree "f7eb5df2e465ab621b1db3f5714850d6732cfed2">]
197+
198+ >>> tree.blobs # blobs are files
199+ [<git.Blob "a871e79d59cf8488cac4af0c8f990b7a989e2b53">,
200+ <git.Blob "3594e94c04db171e2767224db355f514b13715c5">,
201+ <git.Blob "e79b05161e4836e5fbf197aeb52515753e8d6ab6">,
202+ <git.Blob "94954abda49de8615a048f8d2e64b5de848e27a1">]
203+
204+ Its useful to know that a tree behaves like a list with the ability to
205+ query entries by name.
206+
207+ >>> tree[0 ] == tree[' dir' ]
208+ <git.Tree "f7eb5df2e465ab621b1db3f5714850d6732cfed2">
209+ >>> for entry in tree: do_something(entry)
173210
174211 >>> contents.name
175212 'test'
@@ -223,6 +260,15 @@ You can also get a blob directly from the repo if you know its name.
223260
224261 >>> repo.blob(" b19574431a073333ea09346eafd64e7b1908ef49" )
225262 <git.Blob "b19574431a073333ea09346eafd64e7b1908ef49">
263+
264+ Handling Remotes
265+ ****************
266+
267+ Obtaining Diff Information
268+ **************************
269+
270+ Switching Branches
271+ ******************
226272
227273What Else?
228274**********
0 commit comments