@@ -24,68 +24,68 @@ initialize GitPython with a bare repository.
2424A repo object provides high-level access to your data, it allows you to create
2525and delete heads, tags and remotes and access the configuration of the
2626repository.
27-
28- >>> repo.config_reader() # get a config reader for read-only access
29- >>> repo.config_writer() # get a config writer to change configuration
27+
28+ >>> repo.config_reader() # get a config reader for read-only access
29+ >>> repo.config_writer() # get a config writer to change configuration
3030
3131Query the active branch, query untracked files or whether the repository data
3232has been modified.
33-
34- >>> repo.is_dirty()
35- False
36- >>> repo.untracked_files()
37- ['my_untracked_file']
38-
33+
34+ >>> repo.is_dirty()
35+ False
36+ >>> repo.untracked_files()
37+ ['my_untracked_file']
38+
3939Clone from existing repositories or initialize new empty ones.
4040
41- >>> cloned_repo = repo.clone(" to/this/path" )
42- >>> new_repo = repo.init(" path/for/new/repo" )
43-
41+ >>> cloned_repo = repo.clone(" to/this/path" )
42+ >>> new_repo = repo.init(" path/for/new/repo" )
43+
4444Archive the repository contents to a tar file.
4545
46- >>> repo.archive(open (" repo.tar" ,' w' ))
47-
46+ >>> repo.archive(open (" repo.tar" ,' w' ))
47+
4848Examining References
4949********************
5050
5151References are the tips of your commit graph from which you can easily examine
5252the history of your project.
5353
5454 >>> heads = repo.heads
55- >>> master = heads.master # lists can be accessed by name for convenience
56- >>> master.commit # the commit pointed to by head called master
57- >>> master.rename(" new_name" ) # rename individual heads or
55+ >>> master = heads.master # lists can be accessed by name for convenience
56+ >>> master.commit # the commit pointed to by head called master
57+ >>> master.rename(" new_name" ) # rename individual heads or
5858
5959Tags are (usually immutable) references to a commit and/or a tag object.
6060
61- >>> tags = repo.tags
62- >>> tagref = tags[0 ]
63- >>> tagref.tag # tags may have tag objects carrying additional information
64- >>> tagref.commit # but they always point to commits
65- >>> repo.delete_tag(tagref) # delete or
66- >>> repo.create_tag(" my_tag" ) # create tags using the repo
67-
61+ >>> tags = repo.tags
62+ >>> tagref = tags[0 ]
63+ >>> tagref.tag # tags may have tag objects carrying additional information
64+ >>> tagref.commit # but they always point to commits
65+ >>> repo.delete_tag(tagref) # delete or
66+ >>> repo.create_tag(" my_tag" ) # create tags using the repo
67+
6868A symbolic reference is a special case of a reference as it points to another
6969reference instead of a commit
7070
7171Modifying References
7272********************
7373You can easily create and delete reference types or modify where they point to.
7474
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
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
7878
7979Create or delete tags the same way except you may not change them afterwards
8080
81- >>> new_tag = repo.create_tag(' my_tag' , ' my message' )
82- >>> repo.delete_tag(new_tag)
83-
81+ >>> new_tag = repo.create_tag(' my_tag' , ' my message' )
82+ >>> repo.delete_tag(new_tag)
83+
8484Change the symbolic reference to switch branches cheaply ( without adjusting the index
8585or the working copy )
8686
87- >>> new_branch = repo.create_head(' new_branch' )
88- >>> repo.head.reference = new_branch
87+ >>> new_branch = repo.create_head(' new_branch' )
88+ >>> repo.head.reference = new_branch
8989
9090Understanding Objects
9191*********************
@@ -98,43 +98,43 @@ Git only knows 4 distinct object types being Blobs, Trees, Commits and Tags.
9898In Git-Pyhton, all objects can be accessed through their common base, compared
9999and hashed, as shown in the following example.
100100
101- >>> hc = repo.head.commit
102- >>> hct = hc.tree
103- >>> hc != hct
104- >>> hc != repo.tags[0 ]
105- >>> hc == repo.head.reference.commit
106-
101+ >>> hc = repo.head.commit
102+ >>> hct = hc.tree
103+ >>> hc != hct
104+ >>> hc != repo.tags[0 ]
105+ >>> hc == repo.head.reference.commit
106+
107107Basic fields are
108108
109- >>> hct.type
110- 'tree'
111- >>> hct.size
112- 166
113- >>> hct.sha
114- 'a95eeb2a7082212c197cabbf2539185ec74ed0e8'
115- >>> hct.data # returns string with pure uncompressed data
116- '...'
117- >>> len (hct.data) == hct.size
118-
109+ >>> hct.type
110+ 'tree'
111+ >>> hct.size
112+ 166
113+ >>> hct.sha
114+ 'a95eeb2a7082212c197cabbf2539185ec74ed0e8'
115+ >>> hct.data # returns string with pure uncompressed data
116+ '...'
117+ >>> len (hct.data) == hct.size
118+
119119Index Objects are objects that can be put into gits index. These objects are trees
120120and blobs which additionally know about their path in the filesystem as well as their
121121mode.
122122
123- >>> hct.path # root tree has no path
124- ''
125- >>> hct.trees[0 ].path # the first subdirectory has one though
126- 'dir'
127- >>> htc.mode # trees have mode 0
128- 0
129- >>> ' %o ' % htc.blobs[0 ].mode # blobs have a specific mode though comparable to a standard linux fs
130- 100644
131-
123+ >>> hct.path # root tree has no path
124+ ''
125+ >>> hct.trees[0 ].path # the first subdirectory has one though
126+ 'dir'
127+ >>> htc.mode # trees have mode 0
128+ 0
129+ >>> ' %o ' % htc.blobs[0 ].mode # blobs have a specific mode though comparable to a standard linux fs
130+ 100644
131+
132132Access 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
135- >>> htc.blobs[0 ].stream_data(my_stream) # write data to given stream
136-
137-
133+ >>> htc.data # binary tree data
134+ >>> htc.blobs[0 ].data_stream # stream object to read data from
135+ >>> htc.blobs[0 ].stream_data(my_stream) # write data to given stream
136+
137+
138138The Commit object
139139*****************
140140
@@ -171,7 +171,7 @@ The above will return commits 21-30 from the commit list.
171171 >>> headcommit.author
172172 <git.Actor "Michael Trier <mtrier@gmail.com>">
173173
174- >>> headcommit.authored_date # seconds since epoch
174+ >>> headcommit.authored_date # seconds since epoch
175175 1256291446
176176
177177 >>> headcommit.committer
@@ -184,7 +184,7 @@ The above will return commits 21-30 from the commit list.
184184 'cleaned up a lot of test information. Fixed escaping so it works with
185185 subprocess.'
186186
187- Note: date time is represented in a `seconds since epock `_ format. Conversion to
187+ Note: date time is represented in a `` seconds since epock `` format. Conversion to
188188human readable form can be accomplished with the various time module methods.
189189
190190 >>> import time
@@ -216,14 +216,14 @@ the root tree of the latest commit on the master branch.
216216
217217Once you have a tree, you can get the contents.
218218
219- >>> tree.trees # trees are subdirectories
219+ >>> tree.trees # trees are subdirectories
220220 [<git.Tree "f7eb5df2e465ab621b1db3f5714850d6732cfed2">]
221221
222- >>> tree.blobs # blobs are files
222+ >>> tree.blobs # blobs are files
223223 [<git.Blob "a871e79d59cf8488cac4af0c8f990b7a989e2b53">,
224- <git.Blob "3594e94c04db171e2767224db355f514b13715c5">,
225- <git.Blob "e79b05161e4836e5fbf197aeb52515753e8d6ab6">,
226- <git.Blob "94954abda49de8615a048f8d2e64b5de848e27a1">]
224+ <git.Blob "3594e94c04db171e2767224db355f514b13715c5">,
225+ <git.Blob "e79b05161e4836e5fbf197aeb52515753e8d6ab6">,
226+ <git.Blob "94954abda49de8615a048f8d2e64b5de848e27a1">]
227227
228228Its useful to know that a tree behaves like a list with the ability to
229229query entries by name.
@@ -260,60 +260,60 @@ You can also get a tree directly from the repository if you know its name.
260260As trees only allow direct access to their direct entries, use the traverse
261261method to obtain an iterator to access entries recursively.
262262
263- >>> tree.traverse()
264- <generator object at 0x7f6598bd65a8>
265- >>> for entry in traverse(): do_something(entry)
263+ >>> tree.traverse()
264+ <generator object at 0x7f6598bd65a8>
265+ >>> for entry in traverse(): do_something(entry)
266266
267-
267+
268268The Index Object
269269****************
270270The git index is the stage containing changes to be written to the next commit
271271or where merges finally have to take place. You may freely access and manipulate
272272this information using the Index Object.
273273
274- >>> index = repo.index
275-
274+ >>> index = repo.index
275+
276276Access objects and add/remove entries. Commit the changes.
277277
278- >>> for stage,blob in index.iter_blobs(): do_something(... )
279- Access blob objects
280- >>> for (path,stage),entry in index.entries.iteritems: pass
281- Access the entries directly
282- >>> index.add([' my_new_file' ]) # add a new file to the index
283- >>> index.remove([' dir/existing_file' ])
284- >>> new_commit = index.commit(" my commit message" )
285-
278+ >>> for stage,blob in index.iter_blobs(): do_something(... )
279+ Access blob objects
280+ >>> for (path,stage),entry in index.entries.iteritems: pass
281+ Access the entries directly
282+ >>> index.add([' my_new_file' ]) # add a new file to the index
283+ >>> index.remove([' dir/existing_file' ])
284+ >>> new_commit = index.commit(" my commit message" )
285+
286286Create new indices from other trees or as result of a merge. Write that result to
287287a new index.
288288
289- >>> tmp_index = Index.from_tree(repo, ' HEAD~1' ) # load a tree into a temporary index
290- >>> merge_index = Index.from_tree(repo, ' HEAD' , ' some_branch' ) # merge two trees
291- >>> merge_index.write(" merged_index" )
292-
289+ >>> tmp_index = Index.from_tree(repo, ' HEAD~1' ) # load a tree into a temporary index
290+ >>> merge_index = Index.from_tree(repo, ' HEAD' , ' some_branch' ) # merge two trees
291+ >>> merge_index.write(" merged_index" )
292+
293293Handling Remotes
294294****************
295295
296296Remotes are used as alias for a foreign repository to ease pushing to and fetching
297297from them.
298298
299- >>> test_remote = repo.create_remote(' test' , ' git@server:repo.git' )
300- >>> repo.delete_remote(test_remote) # create and delete remotes
301- >>> origin = repo.remotes.origin # get default remote by name
302- >>> origin.refs # local remote references
303- >>> o = origin.rename(' new_origin' ) # rename remotes
304- >>> o.fetch() # fetch, pull and push from and to the remote
305- >>> o.pull()
306- >>> o.push()
299+ >>> test_remote = repo.create_remote(' test' , ' git@server:repo.git' )
300+ >>> repo.delete_remote(test_remote) # create and delete remotes
301+ >>> origin = repo.remotes.origin # get default remote by name
302+ >>> origin.refs # local remote references
303+ >>> o = origin.rename(' new_origin' ) # rename remotes
304+ >>> o.fetch() # fetch, pull and push from and to the remote
305+ >>> o.pull()
306+ >>> o.push()
307307
308308You can easily access configuration information for a remote by accessing options
309309as if they where attributes.
310310
311- >>> o.url
312- 'git@server:dummy_repo.git'
313-
311+ >>> o.url
312+ 'git@server:dummy_repo.git'
313+
314314Change configuration for a specific remote only
315- >>> o.config_writer.set(" url" , " other_url" )
316-
315+ >>> o.config_writer.set(" url" , " other_url" )
316+
317317Obtaining Diff Information
318318**************************
319319
@@ -325,30 +325,30 @@ Diffs can be made between Index and Trees, Index and the working tree, trees and
325325trees as well as trees and the working copy. If commits are involved, their tree
326326will be used implicitly.
327327
328- >>> hcommit = repo.head.commit
329- >>> idiff = hcommit.diff() # diff tree against index
330- >>> tdiff = hcommit.diff(' HEAD~1' ) # diff tree against previous tree
331- >>> wdiff = hcommit.diff(None ) # diff tree against working tree
332-
333- >>> index = repo.index
334- >>> index.diff() # diff index against itself yielding empty diff
335- >>> index.diff(None ) # diff index against working copy
336- >>> index.diff(' HEAD' ) # diff index against current HEAD tree
328+ >>> hcommit = repo.head.commit
329+ >>> idiff = hcommit.diff() # diff tree against index
330+ >>> tdiff = hcommit.diff(' HEAD~1' ) # diff tree against previous tree
331+ >>> wdiff = hcommit.diff(None ) # diff tree against working tree
332+
333+ >>> index = repo.index
334+ >>> index.diff() # diff index against itself yielding empty diff
335+ >>> index.diff(None ) # diff index against working copy
336+ >>> index.diff(' HEAD' ) # diff index against current HEAD tree
337337
338338The item returned is a DiffIndex which is essentially a list of Diff objects. It
339339provides additional filtering to find what you might be looking for
340340
341- >>> for diff_added in wdiff.iter_change_type(' A' ): do_something(diff_added)
341+ >>> for diff_added in wdiff.iter_change_type(' A' ): do_something(diff_added)
342342
343343Switching Branches
344344******************
345345To switch between branches, you effectively need to point your HEAD to the new branch
346346head and reset your index and working copy to match. A simple manual way to do it
347347is the following one.
348348
349- >>> repo.head.reference = repo.heads.other_branch
350- >>> repo.head.reset(index = True , working_tree = True
351-
349+ >>> repo.head.reference = repo.heads.other_branch
350+ >>> repo.head.reset(index = True , working_tree = True
351+
352352The previous approach would brutally overwrite the user's changes in the working copy
353353and index though and is less sophisticated than a git-checkout for instance which
354354generally prevents you from destroying your work.
@@ -358,15 +358,15 @@ Using git directly
358358In case you are missing functionality as it has not been wrapped, you may conveniently
359359use the git command directly. It is owned by each repository instance.
360360
361- >>> git = repo.git
362- >>> git.checkout(' head' , b = " my_new_branch" ) # default command
363- >>> git.for_each_ref() # '-' becomes '_' when calling it
364-
361+ >>> git = repo.git
362+ >>> git.checkout(' head' , b = " my_new_branch" ) # default command
363+ >>> git.for_each_ref() # '-' becomes '_' when calling it
364+
365365The return value will by default be a string of the standard output channel produced
366366by the command.
367367
368368Keyword arguments translate to short and long keyword arguments on the commandline.
369- The special notion `git.command(flag=True) `_ will create a flag without value like
369+ The special notion `` git.command(flag=True) `` will create a flag without value like
370370``command --flag ``.
371371
372372If ``None `` is found in the arguments, it will be dropped silently. Lists and tuples
0 commit comments