栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python合并master到各开发分支

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python合并master到各开发分支

  • 背景
    处于配置管理一职,在每次发布上线后,需要将master分支内容合并到各开发分支
  • python模块
    涉及到git和repo库
from git import Repo
from git import Git

conflict_branch = []
# 路径
repo = Repo("D:/gitlab-1/lis")
gitlab = Git("D:/gitlab-1/lis")
# print(repo.branches)
branches = gitlab.execute('git branch')
branches = branches.replace(' ', '')
branches = branches.replace('*', '').split('n')
print(branches)
print(len(branches))
cnt = 0
for b in branches:
    if b == 'master':
        continue
    gitlab.checkout(b)
    cnt += 1
    # 当前分支
    print("================当前进行中的分支 (%d)===============" % cnt)
    print(repo.active_branch)
    # git pull
    # repo.remote().pull()  # git pull -v origin
    gitlab.execute('git pull')
    try:
        gitlab.execute('git merge origin/master')
        gitlab.execute('git push origin '+b)
        # gitlab.execute('git push')
    except Exception as e:
        gitlab.execute('git merge --abort')
        conflict_branch.append(b)

print("===============conflict================")
print(conflict_branch)

运行情况如下:

  • 结语
    当前只适用于目前的情况,出现冲突需要手动解决。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/269074.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号