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

@icode-js/icode

v3.4.0

Published

Modern git workflow CLI with robust parent-repo and hook handling

Readme

@icode-js/icode v3

@icode-js/icode 是一个面向 Git 日常操作的命令行工具,安装后可直接使用 icode 命令。

目标:

  • 更稳定地处理复杂 Git 场景
  • 更好支持 husky/git hooks 校验链路
  • 默认识别“继承父级 Git 仓库”的目录结构
  • 提供面向人类和 AI agent 的安全场景入口,而不是复刻 Git 子命令
  • 采用更现代的 Node 20+ ESM 架构(无运行时第三方依赖)

安装

npm i -g @icode-js/icode

快速开始

icode help # 查看命令总览
icode info
icode ready
icode save -m "feat: add login form"
icode doctor
icode config ai list

Shell Tab 补全

icode 现在支持生成 bash / zsh 的 tab 补全脚本。

临时启用:

source <(icode completion bash)
source <(icode completion zsh)

持久启用可以把对应命令追加到 ~/.bashrc 或 ~/.zshrc。

补全范围包括:

  • 顶层命令和嵌套子命令
  • 已知参数开关与枚举值
  • 常见 Git 分支 / ref
  • icode config ai ... 下已配置的 profile 名称

全局参数

  • -R, --remote <name>:指定本次使用的 remote(写在命令名前面,例如 icode --remote upstream sync)
  • -h, --help:查看帮助(也可 icode <command> -h 查看子命令参数)
  • -d, --debug:开启调试日志(输出更多细节)

命令一览

| 场景 | 命令 | | --- | --- | | 日常 | ready save push sw checkout stash log sync | | 整理历史 | amend fixup migrate clean | | 兜底 | undo rescue | | 协作与发布 | pr open tag release | | AI | ai codereview explain | | 配置与环境 | config doctor info completion |

通用约定

remote 选择

所有命令不再写死 origin,按以下优先级选择 remote:

  1. 命令行 --remote <name>(或环境变量 ICODE_REMOTE),不存在时直接报错
  2. 仓库 .icoderc.json 的 remote
  3. 全局配置 defaults.remote(icode config set remote upstream)
  4. 当前分支 upstream 所在的 remote
  5. origin,没有时取第一个 remote

fetch 默认只拉取选中的 remote,不再 fetch --all。

仓库级配置 .icoderc.json

放在仓库根目录、可以提交进仓库,团队共享。icode config init 会按当前仓库生成:

{
  "remote": "origin",
  "defaultBranch": "main",
  "protectedBranches": ["main", "release"],
  "save": {
    "maxFileSizeMB": 5,
    "sensitivePatterns": ["*.secret.json"],
    "allowPatterns": ["fixtures/*.pem"]
  }
}

恢复点

会改写历史或删除分支的操作执行前,都会自动把相关分支的位置记到 refs/icode/backup/<时间>/ 下: undo(reset)、push(本地 merge / 强推)、sync、migrate、amend、fixup、clean、rescue --reset。 undo --mode hard 还会备份已跟踪文件的未提交改动。恢复点不会被 push,也不会出现在分支列表里,用 icode rescue 查看和找回。

提交前风险扫描

save、push、amend、fixup 提交前会扫描将要提交的文件:

  • 敏感文件名:.env、*.pem、*.key、id_rsa、credentials.json、*.tfstate 等(.env.example 这类模板不算)
  • 疑似密钥内容:私钥、AWS / GitHub / GitLab / Slack / OpenAI / Google / npm token
  • 大文件:默认超过 5MB

发现风险默认停止,确认无误可加 --allow-risky。

交互与输出

  • 在终端里直接运行 icode 会显示常用操作菜单,选中即执行(可以打字过滤)。
  • 所有选择都用方向键 ↑↓ + 回车;选项多时可以直接打字过滤,选项少时可以按数字快速选;多选用空格勾选、a 全选。确认框直接按 y / n。
  • 尽量用选择代替输入:
    • save / push 不传 -m 时进入提交信息向导:AI 生成,或选类型 → 选 scope(根据改动文件自动推荐)→ 只写一句描述
    • AI 生成提交信息后可以选择:直接使用 / 修改标题 / 重新生成 / 取消
    • push 不写目标分支时可以选“只推当前分支”或勾选要合并的分支
    • checkout / sync / clean / tag / amend / pr create 不带参数时都会给出可选项
    • config 的 AI 配置向导内置常见服务和模型(OpenAI、DeepSeek、通义、智谱、Kimi、Anthropic、Ollama)
  • 输出统一配色:分支、提交、tag、路径、链接用固定颜色,结果用 ✔ ▲ ✖ 标识。
  • 颜色只在终端中显示;输出到管道或文件时自动去掉。可用 NO_COLOR=1 关闭、FORCE_COLOR=1 强制开启。
  • 加 -y 或在非交互环境(CI、脚本)中运行时,不会出现任何交互提示。

JSON 输出

大多数命令支持 --json:stdout 只输出结构化结果(统一带 ok 字段),普通日志改走 stderr。 命令失败时 stdout 输出 {"ok": false, "error": {"code": "...", "message": "...", "exitCode": 2}}。

AI 能力配置

先配置一个 AI profile(支持 OpenAI/Anthropic/Ollama 三种接口格式):

icode config ai set openai \
  --format openai \
  --base-url https://api.openai.com/v1 \
  --api-key sk-xxx \
  --model gpt-4o-mini \
  --activate

Anthropic 示例:

icode config ai set claude \
  --format anthropic \
  --base-url https://api.anthropic.com/v1 \
  --api-key xxx \
  --model claude-3-5-sonnet-20241022 \
  --activate

Ollama 本地模型示例:

icode config ai set ollama \
  --format ollama \
  --base-url http://127.0.0.1:11434 \
  --model qwen2.5:7b \
  --activate

常用命令:

icode config ai list
icode config ai show
icode config ai use claude
icode config ai test

可选:为常用命令预设默认 options(命令行显式传参优先级更高):

icode config ai options set commit --json '{"profile":"ollama","lang":"zh","yes":true}'
icode config ai options set explain --json '{"profile":"ollama","base":"origin/main"}'
icode config ai options set push --json '{"aiProfile":"ollama","aiCommitLang":"zh"}'

健康检查

icode doctor
icode doctor --json

doctor 会检查 Git 命令、当前 remote、hooks、AI profile 与平台 token,并给出修复建议。建议新成员初始化环境后先执行一次。

参数说明:

  • --repo-mode auto|strict:仓库模式(自动继承父仓库/禁止继承)
  • --json:输出机器可读 JSON,适合脚本或 CI 读取
  • -h, --help:查看帮助

核心命令

ready

icode ready
icode ready --json

ready 是继续开发、保存或推送前的场景化检查入口,不会修改 Git 状态。它会检查:

  • 当前是否在明确分支上
  • 是否存在未完成的 merge/rebase/cherry-pick/revert
  • 是否存在未提交改动或冲突文件
  • 当前分支与 upstream 的 ahead/behind 关系
  • AI profile 与远程合并配置是否可用

参数说明:

  • --repo-mode auto|strict:仓库模式(自动继承父仓库/禁止继承)
  • --json:输出机器可读 JSON,适合 AI agent 或脚本判断下一步
  • -h, --help:查看帮助

save

icode save -m "feat: add login form"
icode save --ai-commit -y
icode save -m "fix: adjust copy" --dry-run
icode save --ai-commit --dry-run --json

save 是安全快速提交场景:检查状态 -> 风险扫描 -> 暂存 -> 创建本地 commit。它不会 push,也不会隐式生成提交信息。

icode save -m "fix: typo" src/login.vue   # 只提交指定路径
icode save --staged-only -m "chore: part"  # 只提交已 git add 的内容
  • 无改动会直接失败
  • 存在冲突会直接失败
  • 存在未完成 Git 操作会直接失败
  • --message 和 --ai-commit 必须二选一
  • --dry-run 只检查并展示计划,不执行 git add 或 git commit
  • --ai-commit 必须使用已配置的 AI profile,不做静默降级

参数说明:

  • -m, --message <msg>:指定提交信息
  • --ai-commit:使用 AI 根据全部未提交改动生成提交信息
  • --profile <name>:指定 AI profile(仅 --ai-commit 使用)
  • --lang <zh|en>:AI 提交信息语言,默认 zh
  • [path...]:只提交这些路径
  • --staged-only:只提交暂存区,不自动 git add
  • --allow-risky:检测到敏感文件 / 疑似密钥 / 大文件时仍继续
  • --dry-run:只检查并展示将提交的信息和风险,不执行 add/commit
  • --json:输出机器可读 JSON
  • --repo-mode auto|strict:仓库模式(自动继承父仓库/禁止继承)
  • --no-verify:commit 时跳过 hook/husky 校验
  • -y, --yes:自动确认 AI 提交
  • -h, --help:查看帮助

checkout

icode checkout <branch> [base] [--push-origin] [--pull-main] [--repo-mode auto|strict]
  • 本地存在分支: 直接切换
  • 远程存在分支: 本地创建 tracking 分支并切换
  • 都不存在: 从 base 或默认主分支创建
  • 执行前要求工作区干净,且不存在未完成的 merge/rebase/cherry-pick/revert

参数说明:

  • <branch>:目标分支名(必填)
  • [base]:新建分支基线,默认主分支
  • --push-origin:新建分支后立即推送到 origin
  • --pull-main:切换后同步主分支到当前分支
  • --autostash:有未提交改动时自动 stash,切换后恢复
  • --json:输出机器可读 JSON
  • --repo-mode auto|strict:仓库模式(自动继承父仓库/禁止继承)
  • --no-verify:跳过 hook/husky 校验
  • -y, --yes:自动确认(跳过交互提示)
  • -h, --help:查看帮助

sw

icode sw            # 交互选择(最近使用在前,显示 ahead/behind)
icode sw login      # 模糊匹配,例如 feature/login
icode sw -          # 切回上一个分支
icode sw -c fix/x   # 新建并切换
icode sw -l         # 只列出
  • 唯一匹配时直接切换,多个匹配时交互选择(-y / 非交互环境下报错并列出候选)
  • -a, --all:候选包含仅存在于远程的分支,选中后自动建 tracking 分支
  • --autostash:未提交改动与目标分支冲突时自动 stash 并在切换后恢复

stash

icode stash                       # 交互:选择 stash 后 pop/apply/show/drop
icode stash save -m "wip: login"  # 默认包含未跟踪文件
icode stash list
icode stash pop 1                 # 等同 stash@{1}
icode stash drop 1 -y

log

icode log                          # 最近 20 条
icode log --mine --since "1 week ago"
icode log --unpushed               # 还没推送的提交
icode log --file src/cli.js -n 5   # 文件历史(跟踪重命名)
icode log --graph
icode log main..HEAD --json

push

icode push [targetBranch...] [-m "commit message"] [--ai-commit] [--pull-main] [--not-push-current] [-r|--remote-merge] [--dry-run]

示例:

icode push -m "feat: release" # 提交并推送当前分支
icode push release test -m "feat: batch publish" -y # 默认本地 merge 推送到多个分支
icode push release test --dry-run # 只查看计划,不执行任何 Git/远程合并副作用
icode push release test -r -y # 使用远程 MR 模式合并到多个目标分支
  • 自动 add + commit + push
  • 存在冲突或未完成 Git 操作时会直接停止
  • 本地 merge 冲突会暂停在目标分支现场;解决冲突后执行 icode continue,会自动暂存、推送该分支、继续处理剩下的目标分支并切回原分支;执行 icode abort 则放弃并切回原分支
  • 支持 --ai-commit 在 push 前自动生成并应用 AI 提交信息
  • 若仓库存在 husky/hooks/commitlint 规则,AI commit 会先扫描本地规范再生成提交信息
  • 支持把当前分支合并到多个目标分支
  • 默认使用本地 merge 模式(会生成 merge commit)
  • 支持远程 PR/MR API 模式(需配置平台密钥)
  • 支持受保护分支策略(通过 icode config protect ... 或 .icoderc.json 管理)
  • 目标分支在本地和远程都不存在时,默认会询问(-y 时直接报错),避免拼错分支名时悄悄新建;确需新建请加 --create-target
  • 本地 merge 和强推前会自动创建恢复点
  • --force 是安全强推:只作用于当前分支,只用 --force-with-lease(以 fetch 之前看到的远程位置为准),拒绝主分支和受保护分支

参数说明:

  • [targetBranch...]:目标分支列表(可多个,空则默认当前分支)
  • -m, --message <msg>:提交信息(未填会提示输入)
  • -y, --yes:自动确认(跳过确认提示)
  • --local-merge:显式声明使用本地 merge 模式(当前为默认行为,会切换分支并生成 merge commit)
  • -r, --remote-merge:改为远程 PR/MR 模式;会先推送源分支,再通过 API 创建合并请求;若发生冲突会暂停,并输出明确失败原因
  • --dry-run:只展示计划,不执行 commit/fetch/pull/push/merge/MR
  • --ai-commit:push 前自动执行 AI commit
  • --ai-profile <name>:指定 AI profile(用于 --ai-commit)
  • --pull-main:提交前同步主分支到当前分支
  • --not-push-current:不推送当前分支,只处理目标分支
  • --force-protected:强制处理配置里的受保护分支
  • -f, --force:安全强推当前分支(--force-with-lease)
  • --create-target:目标分支不存在时允许从当前分支新建
  • --allow-risky:检测到风险文件时仍继续提交
  • --json:输出机器可读 JSON
  • --repo-mode auto|strict:仓库模式(自动继承父仓库/禁止继承)
  • --no-verify:跳过 hook/husky 校验
  • -h, --help:查看帮助

说明:

  • push 的布尔开关(如 --ai-commit、--pull-main、--no-verify、-y)仅在命令行显式传入时生效。

远程合并(-r)支持 GitHub、GitLab、Gitee、Gitea/Forgejo,平台按 remote 域名自动识别:

icode config platform token set github ghp_xxx
icode config platform token set gitlab glpat-xxx
icode config platform host set git.company.com gitlab   # 自建平台域名映射

token 也可以用环境变量:GITHUB_TOKEN / GH_TOKEN、GITLAB_TOKEN、GITEE_TOKEN、GITEA_TOKEN。 旧配置 icode config platform remote-merge set --provider gitlab --api-key xxx 仍然有效。

建议:

  • 密钥按平台维度管理,例如 GitLab / GitHub / 自建平台。
  • GitLab API 地址固定为仓库 remote 对应站点的 /api/v4,无需再单独配置服务地址。
  • 项目/仓库默认启用远程合并;如个别仓库不希望启用,可显式设置 repositories.<repo>.remoteMerge.enabled=false。
  • 远程合并始终根据 origin 自动提取 GitLab 项目地址;若无法识别,会提示你修正仓库 remote 配置。
  • GitLab 审批规则由 merge API 统一判断;若审批不足,会在 merge 阶段输出明确失败原因。
  • GitLab 合并检查会展示等待进度,并在长时间 pending 后超时退出,避免命令无限卡住。
  • 这样更符合密钥复用与安全边界,避免多个仓库重复维护同一平台 API 地址。

ai

icode ai commit [--apply]
icode ai conflict
icode ai codereview
icode codereview [--base origin/main --head HEAD]
  • ai commit: 基于 diff 生成 Conventional Commit 信息;若检测到本地 hook/commitlint 规则,会优先遵循项目规范
  • ai conflict: 解析冲突块并生成合并建议
  • ai codereview: 默认评审暂存区 + 工作区未提交改动;传 --base/--head 时可改为评审分支 diff

参数说明:

  • ai commit 参数
    • --apply:直接使用 AI 信息执行 commit
    • --lang <zh|en>:输出语言(默认 zh)
    • --profile <name>:指定 AI profile
    • --repo-mode auto|strict:仓库模式(自动继承父仓库/禁止继承)
    • --no-verify:commit 时跳过 hook/husky 校验
    • -y, --yes:自动确认(跳过确认提示)
    • -h, --help:查看帮助
  • ai conflict 参数
    • --profile <name>:指定 AI profile
    • --repo-mode auto|strict:仓库模式(自动继承父仓库/禁止继承)
    • -h, --help:查看帮助
  • ai codereview / codereview 参数
    • --base <ref>:指定分支 diff 基线;未传时默认评审暂存区 + 工作区未提交改动
    • --head <ref>:指定分支 diff 终点(默认 HEAD)
    • --focus <text>:评审重点(安全/性能/测试等)
    • --profile <name>:指定 AI profile
    • --repo-mode auto|strict:仓库模式(自动继承父仓库/禁止继承)
    • --dump-response:输出 AI 原始响应(调试数据格式)
    • -h, --help:查看帮助

sync

icode sync [branch...] [--all-local] [--merge-main] [--push]
  • 批量同步多个分支(fetch + pull)
  • 执行前要求当前处于普通分支、工作区干净,且不存在未完成 Git 操作
  • 可选自动同步全部本地分支(--all-local)
  • 可选把主分支自动 merge 到目标分支(--merge-main)
  • 可选同步后自动推送(--push)

参数说明:

  • [branch...]:需要同步的分支列表(可多个)
  • --all-local:自动同步全部本地分支
  • --merge-main:同步后把主分支 merge 到目标分支
  • --rebase:pull 时使用 rebase
  • --push:同步后自动 push
  • --autostash:有未提交改动时自动 stash,结束后恢复(否则要求工作区干净)
  • --json:输出机器可读 JSON
  • -y, --yes:自动确认(跳过确认提示)
  • --repo-mode auto|strict:仓库模式(自动继承父仓库/禁止继承)
  • --no-verify:push 时跳过 hook/husky 校验
  • -h, --help:查看帮助

clean

icode clean                       # 已合并到主分支(优先用远程版本判断)
icode clean --gone -y             # 远程分支已被删除的本地分支
icode clean --stale 90 --dry-run  # 超过 90 天没有新提交的分支
  • 不再切换分支,工作区有改动也可以执行
  • 默认保护当前分支/主分支/配置中的受保护分支
  • 删除前会为所有待删分支创建恢复点,误删可用 icode rescue 找回
  • 可选同步删除远程分支(--remote,仅限已合并的分支)

参数说明:

  • --merged-target <branch>:基于该分支判断“已合并”状态
  • --merged:清理已合并分支(默认;与 --gone / --stale 同用时取并集)
  • --gone:清理远程分支已删除的本地分支
  • --stale <days>:清理超过 N 天没有提交的分支
  • --dry-run:只列出将被删除的分支
  • --json:输出机器可读 JSON
  • --keep <branch|csv>:额外保留分支,可重复或逗号分隔
  • --remote:同时删除远程分支
  • --force:强制删除本地分支(-D)
  • -y, --yes:自动确认(跳过确认提示)
  • --repo-mode auto|strict:仓库模式(自动继承父仓库/禁止继承)
  • -h, --help:查看帮助

tag

icode tag [--name <tag>] [--message <msg>] [--from <ref>]
icode tag --bump auto --dry-run   # 按提交推断下一个语义化版本
icode tag --bump minor -y
icode tag --bump prerelease --preid rc

默认 tag 规则:vYYYYMMDD_NN(例如 v20260309_01)。传 --bump 时改用语义化版本: 破坏性变更(feat!: 或 BREAKING CHANGE)-> major,feat -> minor,其它 -> patch(0.x 版本的破坏性变更只升 minor)。

参数说明:

  • -n, --name <tag>:指定 tag 名(默认 vYYYYMMDD_NN)
  • -b, --bump <kind>:auto | patch | minor | major | prerelease
  • --preid <id>:预发布标识,例如 beta、rc
  • --no-push:只创建本地 tag
  • --dry-run:只计算 tag 名
  • --json:输出机器可读 JSON
  • -y, --yes:不再询问 tag 名
  • -m, --message <msg>:tag 备注
  • --from <ref>:从指定分支/commit 创建 tag
  • --repo-mode auto|strict:仓库模式(自动继承父仓库/禁止继承)
  • --no-verify:跳过 hook/husky 校验
  • -h, --help:查看帮助

release

icode release --dry-run                                   # 预览版本号和 changelog
icode release -y                                          # 打 tag、推送、创建平台 Release
icode release --bump minor --write-changelog --update-package -y

流程:计算版本 -> 生成 changelog(按 Conventional Commits 分组)-> 可选写入 CHANGELOG.md / 更新 package.json 并提交 -> 打 annotated tag 并推送 -> 创建 GitHub / GitLab / Gitee / Gitea Release(没有 token 时只给出 Release 页面链接)。

参数:--bump、--preid、--name、--write-changelog、--changelog-file <path>、--update-package、--no-platform、--draft、--prerelease、--no-push、--dry-run、--json、-y。

pr

icode pr create                 # 先推送当前分支,再创建 PR/MR(标题和正文取自提交)
icode pr create -b release --ai # AI 生成标题和描述
icode pr list --state all
icode pr view                   # 当前分支对应的 PR
icode pr checkout 42            # 检出到本地分支 pr/42(fork 来的 PR 也可以)
icode pr merge 42 --method squash -y
icode pr open
  • 支持 GitHub、GitLab、Gitee、Gitea/Forgejo,按 remote 域名自动识别(--provider 可强制指定)
  • 没有配置 token 时,pr create 会改为在浏览器中打开创建页面
  • icode mr 是 icode pr 的别名

open

icode open                  # 当前分支页面
icode open src/cli.js:42    # 文件指定行
icode open pr               # 当前分支的 PR,没有则打开创建页面
icode open compare release  # 当前分支与 release 的对比
icode open ci               # CI / 流水线
icode open commit HEAD~1 -p # 只打印链接

除 open pr 查询已有 PR 外,都不需要 token。

amend

icode amend -a                    # 把全部未提交改动追加到上一个提交
icode amend src/login.js          # 只追加指定路径
icode amend -m "feat: 新的描述"    # 只改提交信息

上一个提交已推送时会先提示(-y 跳过),之后需要 icode push --force。

fixup

icode fixup -a            # 交互选择当前分支上的某个提交,把改动合进去
icode fixup a1b2c3d -a
icode fixup a1b2c3d --no-rebase

等同 git commit --fixup=<commit> + git rebase -i --autosquash,不会打开编辑器。冲突时用 icode continue / icode abort 处理。

continue / abort

冲突解决后继续:

icode continue
  1. 检查冲突文件里是否还有 <<<<<<< / >>>>>>>,有就列出文件和行号,不会继续
  2. 自动 git add 已解决的文件
  3. 继续 merge / rebase / cherry-pick / revert(不会打开编辑器)
  4. 如果是 push / migrate / sync 中途冲突,接着把剩下的步骤做完:推送当前分支、处理剩余目标分支、切回原分支

放弃:

icode abort

中止进行中的 Git 操作,切回原分支。已经推送成功的分支不会被撤回。

有被中断的操作时,icode ready 会标出来,直接运行 icode 的菜单也会把“继续 / 放弃”放在最前面。 icode undo --recover continue|abort 仍然可用,效果相同。

rescue

icode rescue                                   # 列出恢复点和最近的 HEAD 历史(reflog)
icode rescue restore 20261102-153012-120       # 新建分支指向恢复点(不动当前分支)
icode rescue restore 20261102-153012-120:main --reset   # 把当前分支重置过去
icode rescue restore 20261102-153012-120:worktree       # 找回 hard reset 前的未提交改动
icode rescue restore HEAD@{3} --branch fix/lost
icode rescue prune --keep 20

undo

icode undo [ref] [--mode revert|soft|mixed|hard] [--ref <ref>] [--hash <hash>] [--recover continue|abort|keep]
icode undo --mode revert --ref HEAD --json
  • 向导式撤销命令(交互选择回滚策略)
  • 适合新人或低频 Git 操作场景
  • 也支持非交互参数:--mode + --ref / --hash
  • 支持用位置参数指定 commit hash,例如:icode undo a1b2c3d --mode revert -y
  • 检测到未完成的 merge/rebase/revert/cherry-pick 时,会提示继续或中止
  • reset 模式执行前会自动创建恢复点;hard 模式还会备份已跟踪文件的未提交改动
  • 支持 --json 输出结构化结果;适合 AI agent 判断是否已恢复现场

参数说明:

  • --mode <mode>:回滚模式(revert|soft|mixed|hard)
  • --ref <ref>:回滚目标,默认按 mode 自动给出
  • --hash <hash>:按 commit hash 指定回滚目标(等同 --ref)
  • --recover <action>:冲突恢复策略(continue|abort|keep)
  • --json:输出机器可读 JSON
  • -y, --yes:自动确认(跳过确认提示)
  • --repo-mode auto|strict:仓库模式(自动继承父仓库/禁止继承)
  • -h, --help:查看帮助

migrate

icode migrate <sourceBranch> <targetBranch> [--range <from..to>] [--push]
icode migrate <sourceBranch> <targetBranch> --dry-run --json
  • 将 source 分支的提交迁移到 target(底层是 cherry-pick)
  • 默认迁移 target..source 的增量提交
  • 可通过 --range 精确指定迁移范围
  • 执行前要求工作区干净,且不能存在未完成的 merge/rebase/cherry-pick/revert
  • 支持 --dry-run 输出 checkout/pull/cherry-pick/push 计划,不产生 Git 副作用
  • 支持 --json 输出结构化计划或执行结果,适合 AI agent 消费
  • 如果迁移冲突,解决后执行 icode continue(会接着迁移剩下的提交,带 --push 时自动推送并切回原分支),或执行 icode abort 放弃

参数说明:

  • <sourceBranch>:迁移来源分支
  • <targetBranch>:迁移目标分支
  • -i, --interactive:交互模式(单选/多选 source/target 与迁移范围)
  • --range <from..to>:指定提交范围,例如 main..feature-x
  • --dry-run:只展示迁移计划,不 checkout/pull/cherry-pick/push
  • --json:输出机器可读 JSON
  • --push:迁移后自动推送 target 分支
  • -y, --yes:自动确认(跳过确认提示)
  • --repo-mode auto|strict:仓库模式(自动继承父仓库/禁止继承)
  • --no-verify:推送时跳过 hook/husky 校验
  • -h, --help:查看帮助

config

icode config                        # 交互终端中进入引导式配置(token / AI / remote / 受保护分支 / .icoderc)
icode config list                   # 默认脱敏,--show-secrets 查看原文;同时显示当前仓库的 .icoderc.json
icode config set remote upstream    # 常用项有简写
icode config set main main,develop
icode config set token.github ghp_xxx
icode config set host.git.company.com gitlab
icode config get remote
icode config init                   # 生成团队共享的 .icoderc.json
icode config edit                   # 用 $EDITOR 打开配置文件,保存时校验 JSON
icode config path
icode config protect add main release
icode config platform token show

Key 简写:remote、repo-mode、main、ai-profile、token.<平台>、host.<域名>。 键名里带点时可以用方括号:platforms.hosts[git.company.com]。

参数说明:

  • list:查看全部配置(默认脱敏)
  • path / edit / init:配置文件路径 / 编辑 / 生成仓库配置
  • get <path>:读取指定配置项
  • set <path> <value>:写入配置项(支持数字/布尔/JSON)
  • delete <path>:删除配置项
  • protect list:查看受保护分支
  • protect add <branch...>:添加受保护分支
  • protect remove <branch...>:移除受保护分支
  • ai <subcommand>:AI profile 管理(见上文“AI 能力配置”)
  • platform token show|set|remove:管理各平台 token
  • platform host set|remove:自建平台域名映射
  • platform remote-merge show|set:旧命令,仍可用
  • --repo-mode auto|strict:仓库模式(仅影响 protect)
  • -h, --help:查看帮助

info

icode info
icode info --json

输出 Git 版本、仓库根路径、当前分支、使用的 remote 及来源、.icoderc.json 路径、hook/husky 状态、受保护分支等信息。

复杂场景支持

1) Husky / Git Hook 校验

当 commit/push 被 hooks 拦截时,会明确提示:

  • 当前被 hook 拦截
  • 可使用 --no-verify 进行跳过

示例:

icode push -m "chore: hotfix" --no-verify

2) 继承父级 Git 仓库

当你在子目录执行命令,而 .git 在父目录:

  • 默认 --repo-mode auto:自动定位到父仓库根目录执行
  • --repo-mode strict:检测到继承时直接阻断,避免误操作

3) 非 Git 目录

icode 不会在非 Git 目录中隐式执行 git init。如果需要初始化仓库,请先手动执行 git init,再运行 icode 命令。

开发

npm test
node bin/icode.js help
node bin/icode.js undo

发布

当前 npm 包名:

@icode-js/icode

首次发布 scoped 包请显式指定公开访问权限:

npm publish --access public