0.0.5 • Published 4 months ago

@supos-ce-platform/git-tools v0.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

Git Merge Tools

这是一个用于处理git merge相关操作的工具包,专门为monorepo项目设计。

功能特性

  • 分支合并管理
  • 跨仓库分支合并
  • 远程分支直接合并
  • 冲突解决辅助
  • 合并历史查看
  • 合并撤销操作

安装

pnpm add @supos-ce-platform/git-tools
npm -g install @supos-ce-platform/git-tools

使用方法

基本分支合并

import { GitMergeTools } from '@supos-ce-platform/git-tools';

// 初始化工具实例
const gitTools = new GitMergeTools('/path/to/repo');

// 合并分支
await gitTools.mergeBranch('feature', 'main');

远程分支合并

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

合并源分支到目标分支

abortMerge(): Promise

中止当前的合并操作

resolveConflicts(strategy: 'ours' | 'theirs'): Promise

使用指定策略解决冲突

MultiRepoMerge

mergeRemoteBranches(sourceRepo: string, sourceBranch: string, targetRepo: string, targetBranch: string, options?: object): Promise

合并两个远程分支,更专注于远程分支合并,减少了本地分支操作

参数:

  • sourceRepo: 源仓库名称
  • sourceBranch: 源分支名称
  • targetRepo: 目标仓库名称
  • targetBranch: 目标分支名称
  • options: 合并选项
    • showDiff: 是否在合并前显示差异
    • conflictStrategy: 合并冲突时的自动解决策略 ('ours' | 'theirs')
    • push: 是否推送合并结果

mergeCrossBranch(sourceRepo: string, sourceBranch: string, targetRepo: string, targetBranch: string): Promise

跨仓库合并分支(原始方法)

abortMerge(repo: string): Promise

中止指定仓库的合并操作

resolveConflicts(repo: string, strategy: 'ours' | 'theirs'): Promise

使用指定策略解决指定仓库的冲突

0.0.5

4 months ago

0.0.4

4 months ago

0.0.3

4 months ago

0.0.2

4 months ago

0.0.1

4 months ago