02_git

中文文档
0.3.0发布于 2026/05/12MITTypeScriptCommonJS

A Git implementation in TypeScript — supports init, add, commit, log, status, branching, checkout, and three-way merge

原始使用文档
文档目录7 节
  1. Install
  2. Usage
  3. With global install
  4. With npx (no install needed)
  5. Commands
  6. How it works
  7. License

02_git

A Git implementation written in TypeScript from scratch. Supports core Git operations including init, add, commit, log, status, branching, checkout, and three-way merge with conflict detection.

Install

npm install -g 02_git

Usage

There are two ways to use 02_git:

With global install

If you installed globally with npm install -g 02_git, you get the ts-git command:

ts-git init
ts-git add .
ts-git commit -m "initial commit"
ts-git log

With npx (no install needed)

All commands also work via npx — just prefix with npx 02_git:

npx 02_git init
npx 02_git add .
npx 02_git commit -m "initial commit"
npx 02_git log

Commands

ts-git init                        Initialize a new repository
ts-git add <path>                  Stage a file (use . to stage all)
ts-git commit -m "message"         Commit staged changes
ts-git log                         Show commit history
ts-git status                      Show working tree status
ts-git branch <name>               Create a new branch
ts-git checkout <name>             Switch to a branch
ts-git curr-branch                 Show the current branch
ts-git merge <branch> -m "msg"     Merge a branch into current
ts-git c-merge <branch>            Check for merge conflicts without merging
ts-git help                        Show help message

How it works

02_git stores data in a .tsgit directory with the same conceptual structure as Git:

  • Objects — content-addressed blobs, trees, and commits stored by SHA-1 hash
  • Refs — branch pointers stored as files under refs/heads/
  • HEAD — symbolic ref pointing to the current branch
  • Index — staging area mapping file paths to blob hashes

Merges use a three-way merge algorithm that finds the common ancestor and detects conflicts when both branches modify the same file differently.

License

MIT

版本与发布记录

02_git 共发布 3 个版本,首次发布于 2026/05/12;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.3.0latest2026/05/125 个月前
0.2.02026/05/125 个月前
0.1.02026/05/125 个月前

关于 02_git 的常见问题

02_git 是什么?

TypeScript中的Git实现——支持init、add、commit、log、status、branches、checkout和three-way merge

如何安装 02_git?

在项目目录运行 npm install 02_git,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 ts-git,可以用 npx ts-git 直接运行。

02_git 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

02_git 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

02_git 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

02_git 可以商用吗?

02_git 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

02_git 还在维护吗?

最新版本 0.3.0 发布于 2026/05/12(5 个月前);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2026/05/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。