使用 gitpython,如何检查某个 Git 提交 ID?

Using gitpython, how can I checkout a certain Git commit ID?

签出分支效果很好,但我还需要在给定的 Git 存储库中签出某个提交 ID。

我的意思是相当于

git clone --no-checkout my-repo-url my-target-path
cd my-target-path
git checkout my-commit-id

我如何使用 gitpython 执行此操作?

repo = git.Repo.clone_from(repo_url, repo_path, no_checkout=True)
repo.git.checkout(commit_id)

您可以在 documentation 中找到更多详细信息。