git - 需要在 GitPython 中获取最新合并的提交 SHA id
问题描述
我在 git 中的默认分支是“开发”分支。
我想获得最新合并分支的提交 ID 到我的“开发”分支。git python 可以吗?
在命令行我可以做
git log | grep Merge
然后选择最新的。有没有办法用 gitpython 做到这一点?
谢谢。
解决方案
一旦你有了分支 HEAD commit ( headcommit = repo.head.commit
),你可以:
- 检查它的父母数量:
len(headcommit.parents)
- 如果是一个,则采用其唯一的父级:
headcommit.parents[0]
重复直到你找到一个有多个父级的提交:这将是你的合并提交。
那会效仿git log --merges -n 1
。
OP建议:
headcommit = repo.head.commit
while True:
headcommit = headcommit.parents[0]
if len(headcommit.parents) is not 1: break
print (headcommit
推荐阅读
- flutter - 例外:当配置文件颤动应用程序时,iPhone 11 Pro 不支持配置文件模式
- sql - 在 PostgresSQL 中计算每个产品的增值税
- python - 如何计算命令执行的频率?
- python - 无法在 python 中使用 selenium 获取推文
- javascript - 监听 JS 中的击键模式
- c# - c#中的异步和等待问题
- python - 如何从元组列表中创建一个包含 n 个数组的列表,每个元组包含 n 个数组?(除了 for 循环)
- nfc - 安装小程序时如何设置非接触式通信的系统参数?
- arrays - Google 表格按升序排序
- html - 如何并排对齐
我想使用一个很棒的字体图标作为项目符号,但是 h5-tag 从 fa-icon 开始,而不是在同一行。
时间戳在线转换