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