GitPython repo.git.checkout 未正确签出分支

2024-02-16

我正在使用以下代码在 python 代码中签出或切换分支,

repo.git.checkout('branch_name')

但是当代码稍后执行时仍然引用“master”分支代码。

我正在使用 GitPython 版本 2.1.11。


import git
repo = git.Repo("/home/user/.emacs.d")

要结帐分支:

  • 查看可用的分支
>>> repo.heads
[<git.Head "refs/heads/master">, <git.Head "refs/heads/straight">]
  • 您可以像这样使用分支名称:
>>> repo.heads.straight.checkout()
<git.Head "refs/heads/straight">

分支更改为straight

如果你想使用直接git https://gitpython.readthedocs.io/en/stable/tutorial.html#using-git-directly

>>> repo.git.checkout("master")
"Your branch is up-to-date with 'origin/master'."

分支更改为master

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

GitPython repo.git.checkout 未正确签出分支 的相关文章

随机推荐