Source From Here
Question
In a python script, I try to checkout a tag after cloning a git repository. I use GitPython 0.3.2.
With this code I have an error:
If I replace the tag name with a branch name, I have no problem. I didn't find informations in GitPython documentation. And if I try to checkout the same tag in a shell, I have non problem. Do you know how can I checkout a git tag in python ?
HowTo
Assuming you cloned the repository in 'path/to/repo', just try this:
In a python script, I try to checkout a tag after cloning a git repository. I use GitPython 0.3.2.
- #!/usr/bin/env python
- import git
- g = git.Git()
- g.clone("user@host:repos")
- g = git.Git(repos)
- g.execute(["git", "checkout", "tag_name"])
If I replace the tag name with a branch name, I have no problem. I didn't find informations in GitPython documentation. And if I try to checkout the same tag in a shell, I have non problem. Do you know how can I checkout a git tag in python ?
HowTo
Assuming you cloned the repository in 'path/to/repo', just try this:
- from git import Git
- g = Git('path/to/repo')
- g.checkout('tag_name')
沒有留言:
張貼留言