章节 ▾
第二版
-
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上找到。