使用gitpython,我如何检出特定的Git提交ID?

14

检出分支很好用,但我也需要在给定的Git存储库中检出特定的提交ID。

我的意思是相当于

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

如何使用gitpython完成此操作?

1个回答

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

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


6
非常感谢!我看了文档,但是对我来说不太清楚。 - eerriicc

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接