UNPKG

@supos-ce-platform/git-tools

Version:

Supos ce platform Git tools, supos, ce, platform, git tools

92 lines (67 loc) 2.65 kB
# Git Merge Tools 这是一个用于处理git merge相关操作的工具包,专门为monorepo项目设计。 ## 功能特性 - 分支合并管理 - 跨仓库分支合并 - 远程分支直接合并 - 冲突解决辅助 - 合并历史查看 - 合并撤销操作 ## 安装 ```bash pnpm add @supos-ce-platform/git-tools npm -g install @supos-ce-platform/git-tools ``` ## 使用方法 ### 基本分支合并 ```typescript import { GitMergeTools } from '@supos-ce-platform/git-tools'; // 初始化工具实例 const gitTools = new GitMergeTools('/path/to/repo'); // 合并分支 await gitTools.mergeBranch('feature', 'main'); ``` ### 远程分支合并 ```typescript import { MultiRepoMerge } from '@supos-ce-platform/git-tools'; // 初始化工具实例 const multiRepoMerge = new MultiRepoMerge(); // 合并远程分支(优化版本) await multiRepoMerge.mergeRemoteBranches( 'source-repo', // 源仓库名称 'feature-branch', // 源分支名称 'target-repo', // 目标仓库名称 'main', // 目标分支名称 { showDiff: true, // 显示将要合并的差异 conflictStrategy: 'ours', // 冲突解决策略:'ours'使用我们的更改,'theirs'使用他们的更改 push: true // 是否推送合并结果 } ); ``` ## API文档 ### GitMergeTools #### mergeBranch(source: string, target: string): Promise<void> 合并源分支到目标分支 #### abortMerge(): Promise<void> 中止当前的合并操作 #### resolveConflicts(strategy: 'ours' | 'theirs'): Promise<void> 使用指定策略解决冲突 ### MultiRepoMerge #### mergeRemoteBranches(sourceRepo: string, sourceBranch: string, targetRepo: string, targetBranch: string, options?: object): Promise<void> 合并两个远程分支,更专注于远程分支合并,减少了本地分支操作 **参数:** - `sourceRepo`: 源仓库名称 - `sourceBranch`: 源分支名称 - `targetRepo`: 目标仓库名称 - `targetBranch`: 目标分支名称 - `options`: 合并选项 - `showDiff`: 是否在合并前显示差异 - `conflictStrategy`: 合并冲突时的自动解决策略 ('ours' | 'theirs') - `push`: 是否推送合并结果 #### mergeCrossBranch(sourceRepo: string, sourceBranch: string, targetRepo: string, targetBranch: string): Promise<void> 跨仓库合并分支(原始方法) #### abortMerge(repo: string): Promise<void> 中止指定仓库的合并操作 #### resolveConflicts(repo: string, strategy: 'ours' | 'theirs'): Promise<void> 使用指定策略解决指定仓库的冲突