有没有纯Python 的Git 实现?

发布于 2024-10-23 14:55:21 字数 26 浏览 2 评论 0原文

有没有纯Python 的Git 实现?

Is there implementation of Git in pure Python?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

同尘 2024-10-30 14:55:21

找到德威

Dulwich 是纯 Python
Git 文件格式的实现
和协议。

该项目以村庄命名
Git 先生和夫人住在
蒙蒂·派森素描。

看起来像一个低级库,API 在我看来并不友好,但是 Github 页面

Found Dulwich:

Dulwich is a pure-Python
implementation of the Git file formats
and protocols.

The project is named after the village
in which Mr. and Mrs. Git live in the
Monty Python sketch.

Looks like a low-level library, the API did not appear friendly to my eyes, but there's a tutorial on the Github page

蓝眼睛不忧郁 2024-10-30 14:55:21

我知道这个问题相当老了,但我只是想我会为下一个人添加这个问题。接受的答案提到了德威并提到它的水平相当低(这也是我的观点)。我发现 gittle 它是 Dulwich 的高级包装器。它相当容易使用。

安装

$ pip install gittle

示例(取自项目的 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)

从路径初始化存储库

repo = Gittle.init(path)

获取存储库信息

# 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')

提交

# 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="[email protected]", message="This is a commit")

Pull

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()

Push

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()

Branch

# 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)

这些只是我认为最常用的部分(再次从项目的 README.md 中提取) -案例。如果您需要更多,您应该自己检查该项目。

I know that this question is rather old, but I just thought I would add this for the next guy. The accepted answer mentions Dulwich and mentions that it is rather low-level (which is also my opinion). I found gittle which is a high-level wrapper around Dulwich. It's rather easy to use.

Install

$ pip install gittle

Examples (taken from the project's README.md):

Clone a repository

from gittle import Gittle

repo_path = '/tmp/gittle_bare'
repo_url = 'git://github.com/FriendCode/gittle.git'

repo = Gittle.clone(repo_url, repo_path)

Init repository from a path

repo = Gittle.init(path)

Get repository information

# 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')

Commit

# 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="[email protected]", message="This is a commit")

Pull

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()

Push

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()

Branch

# 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)

These are just the parts (again pulled from the project's README.md) which I think would be most common use-cases. You should check out the project yourself if you need more than this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文