02 _git
一个用TypeScript从头开始编写的Git实现。支持核心Git操作,包括初始化、添加、提交、日志、状态、分支、签出和冲突检测的三方合并。
安装
npm install -g 02_git
使用
使用02_git有两种方式:
使用全局安装
如果全局安装了 npm install -g 02_git,你会得到 ts-git 命令:
ts-git init
ts-git add .
ts-git commit -m "initial commit"
ts-git log
使用npx(无需安装)
所有的命令都可以通过npx来工作——只是用 npx 02_git:
npx 02_git init
npx 02_git add .
npx 02_git commit -m "initial commit"
npx 02_git log
命令
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
它是如何工作的
02_git将数据存储在 .tsgit 目录,具有与Git相同的概念结构:
- 对象 -由SHA-1哈希存储的内容寻址blob、树和提交
- 参考文献 分支指针作为文件存储在
refs/heads/ - 头 -指向当前分支的符号引用
- 指数 -暂存区映射文件路径到blob哈希值
merge使用三向合并算法,该算法查找共同的祖先,并在两个分支以不同方式修改同一文件时检测冲突。
许可证
麻省理工学院