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

1

17

Checking out a branch works well, but I also need to check out a certain commit ID in a given Git repository.

I mean the equivalent of

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

How can I do this with gitpython?

Sizar answered 25/11, 2019 at 10:45 Comment(0)
X
23
repo = git.Repo.clone_from(repo_url, repo_path, no_checkout=True)
repo.git.checkout(commit_id)

You can find more details in the documentation.

Xerox answered 25/11, 2019 at 14:47 Comment(1)
Thanks a lot! I looked at the documentation, but it was not clear to me.Sizar

© 2022 - 2024 — McMap. All rights reserved.