@git-lazy/subtree
v2.0.3
Published
Programmatic wrapper for git subtree operations including add, push, pull, and split
Downloads
428
Maintainers
Readme
@git-lazy/subtree
Programmatic wrapper for git subtree operations including add, push, pull, and split
Installation
npm install @git-lazy/subtree
# or
pnpm add @git-lazy/subtree
# or
yarn add @git-lazy/subtreeUsage
import { subtreeAdd, subtreePush, subtreePull, subtreeSplit } from '@git-lazy/subtree';
// 新增 subtree / Add subtree
await subtreeAdd({
prefix: 'packages/my-lib',
remote: 'https://github.com/user/my-lib.git',
branch: 'main',
});
// 推送 subtree / Push subtree
await subtreePush({
prefix: 'packages/my-lib',
remote: 'origin',
branch: 'main',
});
// 拉取 subtree / Pull subtree
await subtreePull({
prefix: 'packages/my-lib',
remote: 'origin',
branch: 'main',
});
// 分割 subtree / Split subtree
await subtreeSplit({
prefix: 'packages/my-lib',
branch: 'extracted-branch',
});CLI
# 使用 CLI 工具 / Use CLI tool
npx subtree add --prefix packages/my-lib --remote origin --branch main
npx subtree push --prefix packages/my-lib --remote origin --branch main
npx subtree pull --prefix packages/my-lib --remote origin --branch main
npx subtree split --prefix packages/my-lib --branch extractedAPI
subtreeAdd(options)
新增 git subtree / Add a git subtree
將遠端倉庫的指定分支合併到本地專案的指定前綴路徑 / Merges a specified branch from a remote repository into the local project at the specified prefix path
Parameters:
options(IOptionsCommon) - 通用選項設定 / Common options configurationprefix(string) - 子樹目錄路徑 / Subtree directory pathremote(string) - 遠端倉庫名稱或 URL / Remote repository name or URLbranch(string, optional) - 分支名稱,預設為 'master' / Branch name, defaults to 'master'squash(boolean, optional) - 是否合併提交記錄 / Whether to squash commit historycwd(string, optional) - 工作目錄 / Working directory
Returns: Promise - Git 命令執行結果 / Git command execution result
Example:
await subtreeAdd({
prefix: 'packages/my-lib',
remote: 'https://github.com/user/my-lib.git',
branch: 'main',
squash: true,
});subtreePush(options)
推送 git subtree 到遠端倉庫 / Push a git subtree to a remote repository
將本地指定前綴路徑的變更推送到遠端倉庫的指定分支 / Pushes changes from the local specified prefix path to the specified branch of the remote repository
Parameters:
options(IOptionsCommon) - 通用選項設定 / Common options configurationprefix(string) - 子樹目錄路徑 / Subtree directory pathremote(string) - 遠端倉庫名稱或 URL / Remote repository name or URLbranch(string, optional) - 分支名稱,預設為 'master' / Branch name, defaults to 'master'squash(boolean, optional) - 是否合併提交記錄 / Whether to squash commit historycwd(string, optional) - 工作目錄 / Working directory
Returns: Promise - Git 命令執行結果 / Git command execution result
Example:
await subtreePush({
prefix: 'packages/my-lib',
remote: 'origin',
branch: 'main',
});subtreePull(options)
從遠端倉庫拉取 git subtree 更新 / Pull git subtree updates from a remote repository
從遠端倉庫的指定分支拉取變更並合併到本地指定前綴路徑 / Pulls changes from the specified branch of the remote repository and merges them into the local specified prefix path
Parameters:
options(IOptionsCommon) - 通用選項設定 / Common options configurationprefix(string) - 子樹目錄路徑 / Subtree directory pathremote(string) - 遠端倉庫名稱或 URL / Remote repository name or URLbranch(string, optional) - 分支名稱,預設為 'master' / Branch name, defaults to 'master'squash(boolean, optional) - 是否合併提交記錄 / Whether to squash commit historycwd(string, optional) - 工作目錄 / Working directory
Returns: Promise - Git 命令執行結果 / Git command execution result
Example:
await subtreePull({
prefix: 'packages/my-lib',
remote: 'origin',
branch: 'main',
squash: true,
});subtreeSplit(options)
分割 git subtree 為獨立分支 / Split a git subtree into a separate branch
將指定前綴路徑的歷史記錄提取為獨立分支,可用於建立子模組或獨立倉庫 / Extracts the history of the specified prefix path into a separate branch, useful for creating submodules or standalone repositories
Parameters:
options(IOptionsSplit) - 分割選項設定 / Split options configurationprefix(string) - 子樹目錄路徑 / Subtree directory pathbranch(string) - 分支名稱 / Branch namerejoin(boolean, optional) - 是否重新加入已分割的提交 / Whether to rejoin split commitsignoreJoins(boolean, optional) - 是否忽略之前的 join 記錄 / Whether to ignore previous join recordscwd(string, optional) - 工作目錄 / Working directory
Returns: Promise - Git 命令執行結果 / Git command execution result
Example:
// 基本分割 / Basic split
await subtreeSplit({
prefix: 'packages/my-lib',
branch: 'extracted-branch',
});
// 使用 rejoin 選項繼續累積提交 / Use rejoin option to continue accumulating commits
await subtreeSplit({
prefix: 'packages/my-lib',
branch: 'extracted-branch',
rejoin: true,
});Types
IOptionsCommon
通用選項型別,用於 add/push/pull 操作 / Common options type for add/push/pull operations
IOptionsSplit
Split 選項型別,用於 git subtree split 操作 / Split options type for git subtree split operations
EnumSubtreeCmd
Subtree 命令列舉:add | push | pull | split / Subtree command enumeration
EnumPrefixType
Prefix 類型列舉:ROOT | RELATIVE | ABSOLUTE / Prefix type enumeration
License
ISC
