Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 247
eerriicc Avatar asked Nov 25 '19 10:11

eerriicc


1 Answers

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.

like image 176
gnvk Avatar answered Oct 20 '22 16:10

gnvk