我知道这个问题相当老了,但我只是想我会为下一个人添加这个问题。接受的答案提到了德威并提到它的水平相当低(这也是我的观点)。我发现吉特尔,它是 Dulwich 的高级包装。它相当容易使用。
$ pip install gittle
Run Code Online (Sandbox Code Playgroud)
示例(取自项目的 README.md):
from gittle import Gittle
repo_path = '/tmp/gittle_bare'
repo_url = 'git://github.com/FriendCode/gittle.git'
repo = Gittle.clone(repo_url, repo_path)
Run Code Online (Sandbox Code Playgroud)
repo = Gittle.init(path)
Run Code Online (Sandbox Code Playgroud)
# Get list of objects
repo.commits
# Get list of branches
repo.branches
# Get list of modified files (in current working directory)
repo.modified_files
# Get diff between latest commits
repo.diff('HEAD', 'HEAD~1')
Run Code Online (Sandbox Code Playgroud)
# Stage single file
repo.stage('file.txt')
# Stage multiple files
repo.stage(['other1.txt', 'other2.txt'])
# Do the commit
repo.commit(name="Samy Pesse", email="samy@friendco.de", message="This is a commit")
Run Code Online (Sandbox Code Playgroud)
repo = Gittle(repo_path, origin_uri=repo_url)
# Authentication with RSA private key
key_file = open('/Users/Me/keys/rsa/private_rsa')
repo.auth(pkey=key_file)
# Do pull
repo.pull()
Run Code Online (Sandbox Code Playgroud)
repo = Gittle(repo_path, origin_uri=repo_url)
# Authentication with RSA private key
key_file = open('/Users/Me/keys/rsa/private_rsa')
repo.auth(pkey=key_file)
# Do push
repo.push()
Run Code Online (Sandbox Code Playgroud)
# Create branch off master
repo.create_branch('dev', 'master')
# Checkout the branch
repo.switch_branch('dev')
# Create an empty branch (like 'git checkout --orphan')
repo.create_orphan_branch('NewBranchName')
# Print a list of branches
print(repo.branches)
# Remove a branch
repo.remove_branch('dev')
# Print a list of branches
print(repo.branches)
Run Code Online (Sandbox Code Playgroud)
这些只是我认为最常见用例的部分(再次从项目的 README.md 中提取)。如果您需要更多,您应该自己检查该项目。