Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite395ac9

Browse files
committed
Added tutorial about initializing a repository.
Additionally, for this and future examples, there is a test_doc.pysuite to contain all code mentioned in the docs. That way, we knowif things stop working.Fixesgitpython-developers#236
1 parent048ffa5 commite395ac9

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

‎doc/source/tutorial.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,22 @@ The previous approach would brutally overwrite the user's changes in the working
415415
repo.heads.master.checkout()# checkout the branch using git-checkout
416416
repo.heads.other_branch.checkout()
417417

418+
Initializing a repository
419+
*************************
420+
421+
In this example, we will initialize an empty repository, add an empty file to the index, and commit the change::
422+
423+
repo_dir = 'my-new-repo'
424+
file_name = os.path.join(repo_dir, 'new-file')
425+
426+
r = git.Repo.init(repo_dir)
427+
# This function just creates an empty file ...
428+
touch(file_name)
429+
r.index.add([file_name])
430+
r.index.commit("initial commit")
431+
432+
Please have a look at the individual methods as they usually support a vast amount of arguments to customize their behavior.
433+
418434
Using git directly
419435
******************
420436
In case you are missing functionality as it has not been wrapped, you may conveniently use the git command directly. It is owned by each repository instance::

‎git/test/test_docs.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#-*-coding:utf-8-*-
2+
# test_git.py
3+
# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
4+
#
5+
# This module is part of GitPython and is released under
6+
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
7+
importos
8+
9+
importgit
10+
fromgit.test.libimportTestBase
11+
fromgitdb.test.libimportwith_rw_directory
12+
fromgit.repo.funimporttouch
13+
14+
15+
classTestGit(TestBase):
16+
17+
@with_rw_directory
18+
deftest_add_file_and_commit(self,rw_dir):
19+
repo_dir=os.path.join(rw_dir,'my-new-repo')
20+
file_name=os.path.join(repo_dir,'new-file')
21+
22+
r=git.Repo.init(repo_dir)
23+
# This function just creates an empty file ...
24+
touch(file_name)
25+
r.index.add([file_name])
26+
r.index.commit("initial commit")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp