章节 ▾
第二版
-
1. 起步
-
2. Git 基础
-
3. Git 分支
-
4. 服务器上的 Git
- 4.1 协议
- 4.2 在服务器上部署 Git
- 4.3 生成 SSH 公钥
- 4.4 架设服务器
- 4.5 Git Daemon
- 4.6 Smart HTTP
- 4.7 GitWeb
- 4.8 GitLab
- 4.9 第三方托管服务
- 4.10 小结
-
5. 分布式 Git
-
A1. 附录 A: Git 在其他环境
- A1.1 图形界面
- A1.2 Visual Studio 中的 Git
- A1.3 Visual Studio Code 中的 Git
- A1.4 IntelliJ / PyCharm / WebStorm / PhpStorm / RubyMine 中的 Git
- A1.5 Sublime Text 中的 Git
- A1.6 Bash 中的 Git
- A1.7 Zsh 中的 Git
- A1.8 PowerShell 中的 Git
- A1.9 小结
-
A2. 附录 B: 在应用程序中嵌入 Git
-
A3. 附录 C: Git 命令
A2.5 附录 B:将 Git 嵌入你的应用程序 - Dulwich
Dulwich
还有一个纯 Python 的 Git 实现 - Dulwich。该项目托管在 https://www.dulwich.io/。它旨在提供一个 Git 仓库(本地和远程)的接口,该接口不直接调用 Git,而是使用纯 Python。尽管如此,它还是有可选的 C 扩展,可以显著提高性能。
Dulwich 遵循 Git 的设计,并将 API 分为两个基本级别:plumbing(管道)和 porcelain(瓷器)。
这是一个使用低级 API 访问最后一次提交的提交消息的示例
from dulwich.repo import Repo
r = Repo('.')
r.head()
# '57fbe010446356833a6ad1600059d80b1e731e15'
c = r[r.head()]
c
# <Commit 015fc1267258458901a94d228e39f0a378370466>
c.message
# 'Add note about encoding.\n'
要使用高级 porcelain API 打印提交日志,可以使用
from dulwich import porcelain
porcelain.log('.', max_entries=1)
#commit: 57fbe010446356833a6ad1600059d80b1e731e15
#Author: Jelmer Vernooij <jelmer@jelmer.uk>
#Date: Sat Apr 29 2017 23:57:34 +0000
延伸阅读
API 文档、教程以及有关如何使用 Dulwich 完成特定任务的许多示例可在官方网站 https://www.dulwich.io 上找到。