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

eer*_*icc 7 python-3.x gitpython

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

我的意思是相当于

git clone --no-checkout my-repo-url my-target-path
cd my-target-path
git checkout my-commit-id
Run Code Online (Sandbox Code Playgroud)

我怎样才能用 gitpython 做到这一点?

gnv*_*nvk 9

repo = git.Repo.clone_from(repo_url, repo_path, no_checkout=True)
repo.git.checkout(commit_id)
Run Code Online (Sandbox Code Playgroud)

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

  • 多谢!我查看了文档,但我不清楚。 (2认同)