我正在使用以下代码在python代码中签出或切换分支,
repo.git.checkout('branch_name')
但是当以后执行代码时,仍指的是“主”分支代码。
我正在使用GitPython版本2.1.11。
答案 0 :(得分:0)
import git
repo = git.Repo("/home/user/.emacs.d")
To checkout a branch:
>>> repo.heads
[<git.Head "refs/heads/master">, <git.Head "refs/heads/straight">]
>>> repo.heads.straight.checkout()
<git.Head "refs/heads/straight">
the branch changed to straight
If you want to use git directly
>>> repo.git.checkout("master")
"Your branch is up-to-date with 'origin/master'."
the branch changed to master