在GitPython中签出或列出远程分支 [英] Checkout or list remote branches in GitPython
问题描述
在此模块中,我没有看到用于签出或列出远程/本地分支的选项: https: //gitpython.readthedocs.io/en/stable/
I don't see an option to checkout or list remote/local branches in this module: https://gitpython.readthedocs.io/en/stable/
推荐答案
完成后
from git import Git
g = Git()
(可能还有其他一些命令将g
初始化到您关心的存储库中),g
上的所有属性请求或多或少都转换为对git attr *args
的调用.
(and possibly some other command to init g
to the repository you care about) all attribute requests on g
are more or less transformed into a call of git attr *args
.
因此:
g.checkout("mybranch")
应该做你想做的事.
g.branch()
将列出分支.但是,请注意,这些命令是非常底层的命令,它们将返回git可执行文件将返回的确切代码.因此,不要指望有一个不错的清单.我将是多行的字符串,并且其中一行以星号作为第一个字符.
will list the branches. However, note that these are very low level commands and they will return the exact code that the git executables will return. Therefore, don’t expect a nice list. I’ll just be a string of several lines and with one line having an asterisk as the first character.
在库中可能有一些更好的方法可以做到这一点.例如,在repo.py
中是特殊的active_branch
命令.您必须仔细检查一下源代码并寻找自己.
There might be some better way to do this in the library. In repo.py
for example is a special active_branch
command. You’ll have to go through the source a little and look for yourself.
这篇关于在GitPython中签出或列出远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!