niu-git
原生 Windows Git,无 MSYS:git-for-windows 的真实 C 源码用 MSVC 构建,
不捆 bash、不捆 perl、不捆 OpenSSL——TLS 走 schannel 与 Windows 证书库。
PATH 上的 git 就是 git 本体,git --version 约 14 ms 启动,
脚本部分(hooks、bisect、mergetool)跑在 niubash 的 sh 上。
为什么是 niu-git
Windows 上几乎每个人的 PATH 里都躺着一个「先启动 MSYS2 运行时再干活」的 git: 从 cmd / PowerShell 调用要走 cmd\git.exe launcher,在 Git Bash 里调用还要再付一次 fork, 于是每个 git status 都在为一个你不需要的 POSIX 世界付税。niu-git 的立场很朴素—— git 本体是 C 程序,那就把它当 C 程序原生构建;git 的脚本部分是 shell,那就交给真正的 shell。
快是结构性的,不是调优
Git Bash 的 git 跑在 MSYS2 运行时里(从 cmd / PowerShell 还要再过一道 cmd\git.exe launcher),每次调用都付一遍 POSIX 运行时初始化,在 Git Bash 提示符里还要再付一次 fork。niu-git 的 usr\bin\git.exe 就是 git 本体:一次 CreateProcess,无 MSYS DLL、进程树里无 bash 无 perl。
无 MSYS、无 OpenSSL、无捆绑脚本运行时
MSVC + CMake 构建 git-for-windows 真实 C 源码;TLS 只走 schannel(Windows 证书库),不捆 OpenSSL;zlib / iconv 静态链接进 git.exe(没有 zlib1.dll / iconv-2.dll);shell 脚本部分(hooks、git bisect、git mergetool)由 PATH 上的 niubash sh 承担——不捆 bash,也不捆 perl。
参数保真:引号纪律与消息字面字节
commit -m 载荷、D:\dir\ 路径规格、CJK 与多行消息逐字节存活——引号规则按 Win32 文档行为对齐、零启发式,差分套件 49/49 钉死。POSIX 形路径参数(/d/repo/...)经存在性检查回退转换接受;消息载荷永不改写——消息就是字面字节。
边界诚实:不带的说清楚
perl 命令(send-email、svn、cvs*)不提供而不是运行时才失败;git-gui / gitk(Tcl/Tk)不随发;git grep -P(PCRE2)没有——用 WinuxCmd 的 grep -P。git --version 携带 2.56.0.windows.2.niugit 分布标记,bug 报告能同时定位发行版与上游基线。
核心特性
真 git C 源码,MSVC 原生构建
不是重写也不是模拟:上游 git-for-windows 的 C 源码 + 仓内三枚补丁(#1 schannel 容忍 stale http.sslBackend;#2 POSIX 形路径参数 + 消息守卫;#3 system prefix 自定位),源码永不入仓,CI 拉上游 tarball 打补丁。
~14 ms 启动
wpm flat 布局实测 git --version 13.7 ms 均值 / 11.5 ms 最小值,git status 22.6 ms 均值——对照 Git Bash 侧 45–103 ms。v2.55.0.5 起根入口 launcher 退役:patch #3 让裸 git.exe 自己找到 payload,无包装 hop、无 winuxcmd 分发跳转。
schannel TLS 与凭据不越权
TLS 走 Windows 证书库;你自配的任何凭据 helper(host 级 credential.<url>.helper、Git Credential Manager、gh auth git-credential)照常生效。系统 gitconfig 刻意不设默认 helper(git 按 system→global→local 顺序咨询,系统默认会跑在你自选的 helper 之前);自带 172 KB 的 wincred 小助手读 Windows 凭据管理器里现成的条目。
与 niubash sh 的分工
git 的 shell 脚本部分——hooks、git bisect、git mergetool、git filter-branch、git submodule、git request-pull——跑在 niubash 提供的 sh 上(wpm 索引条目明文 niu-git 接受 POSIX 形 /d/... 参数)。git 二进制管 C 的事,shell 的事交给真正的 shell。
上游测试基线在案
对 CMake 构建跑上游 t/ 套件(t0*、t1[0-4]* 子集):curated subset 2861 ok / 14 例 # TODO known breakage / 0 硬失败;t0001-init 102/103(唯一失败是 includeIf.onbranch 重初始化边缘例)。
随 niubash 一起到货
niubash 1.4.0 的 Windows 发行包经 wpm 预装 niu-git(同批 gawk、ripgrep、fd;ARM64 安装同样预装 niu-git / ripgrep / fd,仅 gawk 限 x64)——装完 niubash,PATH 上的 git 就是原生 git。
安装与快速上手
Windows:niubash 发行包已预装 niu-git(捆绑清单见 niubash 的 scripts/release/preinstall.json;niu-git 与 gawk 为 windows-x64 资产,ARM64 腿只随 ripgrep 与 fd——preinstall.json notes),验证:
git --version 已装过 MinGit shim 的用户迁移(flat 布局需要 WinuxCmd/wpm 1.1.9+):
wpm update winuxcmd
wpm install niugit --force
首跑验证一句:git --version 应输出 2.56.0.windows.2.niugit 形态的版本串——
上游后缀与 niu-git 分布标记都在;装 niubash 的用户无需此步,Windows 发行包已随附 niu-git(x64 与 ARM64)。
深入:速度、原生工具链与 sh 联动
速度对比
Windows x64、warm cache、Python subprocess 计时、15 轮、小仓库(2026-10 实测)。 差距是结构性的:niu-git 一次 CreateProcess 即达 git 本体;Git Bash 侧每调用付 MSYS2 运行时初始化(提示符内再付 fork)。
| PATH 上的 git | git --version | git status --porcelain |
|---|---|---|
| niu-git(flat 布局) | 13.7 ms 均值 / 11.5 ms 最小 | 22.6 ms 均值 / 17.4 ms 最小 |
| Git for Windows mingw64\bin\git.exe | 51.3 ms 均值 | 30.6 ms 均值 |
| Git for Windows cmd\git.exe(PATH 常规入口) | 45.3 ms 均值 | 50.1 ms 均值 |
| Git Bash 提示符内 time git … | 73–103 ms real | — |
MSVC / schannel:原生工具链到底
构建链是 MSVC + CMake(+ vcpkg),TLS 只编 schannel:证书与系统更新走 Windows 证书库, 不携带 OpenSSL 及其随附 dll;zlib 与 iconv 静态链接,git.exe 旁没有运行时搭子。 对从其它 Git 发行版迁来的用户,patch #1 容忍遗留的 http.sslBackend 配置——警告并回落, 而不是拒绝启动。
与 niubash sh 联动
git 的脚本面不是被删掉,是被分工:hooks、git bisect、git mergetool、git filter-branch、
git submodule、git request-pull 交给 PATH 上的 sh——即
niubash 的 sh shim(wpm 索引条目明文 niu-git 接受 POSIX 形
/d/... 参数)。perl 依赖的 send-email / svn / cvs* 则诚实地缺席而非运行时炸裂;
git grep -P 没有时,用 WinuxCmd 的
grep -P。路径方言的总账见 路径与 MSYS。
实测数字
| 指标 | niu-git | 对照 | 来源 |
|---|---|---|---|
| git --version | 13.7 ms 均值 / 11.5 ms 最小(约 ~14 ms) | Git Bash 45–103 ms | niu-git README Speed 表(2026-10 实测) |
| git status --porcelain | 22.6 ms 均值 / 17.4 ms 最小 | GfW cmd\git.exe 50.1 ms 均值 | 同上 |
| 安装体积 | bundle 29 MB / zip 33 MB | MinGit zip 37 MB | niu-git README Status 节 |
| 上游 t/ 套件(curated subset) | 2861 ok / 0 硬失败 | 14 例 # TODO known breakage | niu-git README Test 节 |
| launcher 引号差分 | 49/49 通过 | — | niu-git PR #6 · test-launcher.py |
更新动态
| 版本 | 日期 | 摘要 |
|---|---|---|
v2.56.0.1 | — | 最新 tag:上游基线推进到 git 2.56.0.windows.2,git --version 携带 2.56.0.windows.2.niugit 分布标记(repo-meta 2026-10-19 实测;无 release 页,tag 即版本)。 |
v2.55.0.5 | — | dispatcher 退役:patch #3 自定位让真 mingw64/bin/git.exe 直映 usr\bin\git.exe,wpm flat 实测 git --version 13.7 ms 均值、git status 22.6 ms;wpm/niugit.json 即此版索引条目(sha256/size 与本地构建对齐)。 |
v2.55.0.windows.2 | — | Phase 0 PoC 定稿:MSVC + CMake + vcpkg 构建 git-for-windows v2.55.0.windows.2,zlib/iconv 静态链接,bundle 29 MB;init/add/commit/log/status、schannel https clone、经 PATH 上 sh 执行 hooks 全部验证。 |
niu-git 不在 changelogs.json 的抓取范围(无 release 页、无 CHANGELOG,tag 即版本——FACTS.json products 裁决);上表摘自仓内 README、wpm/niugit.json 与 portal repo-meta 实测 tag。 其余仓库的完整流水见 更新日志。
相关链接
站内
- niubash 产品文档——sh 联动的另一半,Windows 发行包随附 niu-git
- WinuxCmd 产品文档——wpm 与 grep -P 的提供方
- 路径与 MSYS:最大的行为差异 · 基准页(git 启动 ~14 ms 对照 45–103 ms)· 更新日志
站外
- GitHub 仓库 ↗(补丁式仓库:源码永不入仓,CI 拉上游 tarball 打 patches/)
- Tags(版本即 tag)↗
常见问题
niu-git 和 Git for Windows 有什么区别?
同一份 git-for-windows C 源码的 MSVC 原生构建:无 MSYS 层、无 OpenSSL(TLS 走 schannel + Windows 证书库)、不捆绑 shell/perl——launcher 引号按 Win32 文档行为对齐,零启发式。
niu-git 为什么快?
git 启动约 14 ms(Git Bash 实测 45–103 ms);无 DLL 装载与 MSYS 初始化链,进程直接起步。
niu-git 怎么安装?
随 niubash 预装(x64 / arm64 双架构),装好即有:git --version 直接可用,并接受 POSIX 形 /d/... 参数。
niubash 和 Git Bash / WSL 有什么区别?
niubash 是 Rust 写的原生 Windows 程序:不捆绑 MSYS 模拟层,也不需要 WSL 虚拟机。Git Bash 在 spawn 前会启发式改写「看起来像路径」的参数(这正是 MSYS_NO_PATHCONV 咒语存在的原因),niu 的 argv 逐字节原样抵达;安装后全家族约 16 MB,Git Bash 约 440 MB。
性能怎么样?
一次性执行(niu -c true)经专项优化后 19.8ms;niu-git 启动约 14ms(Git Bash 45–103ms);命令替换与子壳类负载比 GNU bash 快 13–62x。全部数字附实测方法与复现产物,见「基准测试」(/benchmarks/)。