【发布时间】:2020-03-13 06:25:14
【问题描述】:
在最新的存储库中,我们执行以下操作:
git checkout HEAD~5
然后使用GitPython,我们可以得到head commit,它是分离的:
import git
repo = git.Repo('.')
head = repo.head
head_commit = head.commit
print(head.is_detached)
> True
GitPython 中有没有办法获取分支中的最后一次提交?
我在想一些类似的事情:
last = repo.active_branch.last_commit # active_branch will throw an error when head is detached.
或
last = head_commit
# I dont even know if talking about child commits makes sense in git.
while last.child is not None:
last = last.child
【问题讨论】:
标签: git gitpython git-detached-head