npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@huangminhua/giff

v1.1.5

Published

git变更内容查询工具

Downloads

1,005

Readme

giff

git 变更内容查询工具,支持查看变更文件列表、变更行详情,并结合 JaCoCo 报告展示单元测试覆盖率。

安装

npm install -g @huangminhua/giff

命令概览

giff [options]

| 选项 | 说明 | |------|------| | -l, --list | 获取变更文件列表 | | -f, --file <path> | 查看指定文件的变更内容详情 | | -j, --jacoco | 展示 JaCoCo 覆盖率信息 | | -c, --commit [commitId] | 指定比较基准 commitId | | -V, --version | 显示版本号 | | -h, --help | 显示帮助信息 |

支持短标志合并,如 -lj-fj path-fjc path commitId

功能详解

1. 列出变更文件 (-l)

获取当前分支相对于主分支(或指定 commit)的变更文件列表,包含已提交和未提交的文件。

# 与主分支比较
giff -l

# 与指定 commit 比较
giff -l -c abc123

# 所有文件(commitId 为 0,视为全部新增)
giff -l -c 0

输出示例:

src/main/java/com/xxx/api/stream/XxxProducer.java
src/main/java/com/xxx/api/stream/YyyConsumer.java
src/main/resources/application.yml

2. 查看文件变更详情 (-f)

展示指定文件对应的git diff结果明细。

giff -f src/main/java/com/xxx/api/stream/XxxProducer.java

# 与指定 commit 比较
giff -f src/main/java/.../XxxProducer.java -c abc123

3. JaCoCo 覆盖率统计 (-l -j)

列出变更文件的同时,展示每个文件的 JaCoCo 单元测试覆盖率,首行显示总计覆盖率。

giff -lj

输出示例:

总计 [行覆盖率: 75.0% (9/12), 分支覆盖率: 50.0% (6/12)]
src/main/java/.../XxxProducer.java [行覆盖率: 100.0% (6/6), 分支覆盖率: 100.0% (6/6)]
src/main/java/.../YyyConsumer.java [行覆盖率: 50.0% (3/6), 分支覆盖率: 0.0% (0/6)]
src/main/java/.../dto/Result.java [非单元测试目标, 无需检测覆盖率]
src/main/resources/application.yml [非单元测试目标, 无需检测覆盖率]

覆盖率计算公式:

  • 行覆盖率 = (fc + pc) / (fc + pc + nc)
  • 分支覆盖率 = (bfc + bpc) / (bfc + bpc + bnc)

其中:

  • fc — 完全覆盖(fully covered)
  • pc — 部分覆盖(partially covered)
  • nc — 未覆盖(not covered)
  • bfc — 分支完全覆盖(branch fully covered)
  • bpc — 分支部分覆盖(branch partially covered)
  • bnc — 分支未覆盖(branch not covered)

4. 文件级行覆盖率详情 (-f -j)

展示指定文件每一行的变更标记和 JaCoCo 覆盖标记。

giff -fj src/main/java/com/xxx/api/stream/XxxProducer.java

输出示例:

行覆盖率: 75.0% (6/8), 分支覆盖率: 50.0% (4/8)
ignore        1) package com.xxx.api.stream;
ignore        2)
fc            3) public class XxxProducer {
pc bpc        4)     if (condition1 && condition2) {
fc            5)         doSomething();
nc            6)         fallback();
ignore        7) }

覆盖标记说明:

| 标记 | 含义 | |------|------| | fc | 完全覆盖 | | fc bfc | 分支完全覆盖 | | pc bpc | 部分覆盖,分支部分覆盖 | | nc | 未覆盖 | | nc bnc | 分支未覆盖 | | ignore | 非变更行,或无 JaCoCo 数据 |

JaCoCo 报告路径推导

工具根据源文件路径自动推导 JaCoCo 报告路径:

源文件:src/main/java/com/xxx/api/stream/XxxProducer.java
报告:  target/jacoco-ut/com.xxx.api.stream/XxxProducer.java.html

规则:去掉 src/main/java/ 前缀,将包路径的 / 替换为 .,拼接到 target/jacoco-ut/ 下,加 .html 后缀。

环境变量

| 变量名 | 说明 | 默认值 | |--------|------|--------| | GIFF_JACOCO_EXCLUDE | 排除 JaCoCo 覆盖率检测的文件正则,逗号分隔 | /dto/,/vo/,/entity/,/po/ |

排除规则默认还会排除:

  • .java 文件
  • src/test 下的测试文件
# 自定义排除规则
GIFF_JACOCO_EXCLUDE="/dto/,/vo/,/entity/,/po/,/enums/" giff -lj

commitId 说明

| 值 | 行为 | |----|------| | 不指定 | 与主分支的 Merge Base 节点比较 | | 具体 commitId | 与指定 commit 比较 | | 0 | 所有文件/行视为新增,适用于统计全量覆盖率 |

主分支自动检测

工具按以下优先级自动检测主分支名:

  1. git rev-parse --abbrev-ref origin/HEAD(远程 HEAD 引用)
  2. 依次尝试本地 mainmastertrunk 分支
  3. 默认 main