Skip to content

工具链备忘(CLI 密集)

仓库卫生

bash
git status -sb
git switch -c fix/typo
git fetch origin
git rebase origin/main
git log --oneline --graph -15
git blame -L 10,40 src/app.ts

暂存与挑选

bash
git add -p
git stash push -m "wip: ai draft"
git stash list
git stash pop

撤销

bash
# 工作区单文件
git restore src/foo.ts

# 取消暂存
git restore --staged src/foo.ts

# 交互回退提交(已推送慎用)
git revert HEAD

Node / 前端

bash
node -v
npm ci
npm run build
npm run test -- --watch=false

# 为什么装了这个包
npm ls lodash
pnpm why axios

package.json scripts 示例

json
{
  "scripts": {
    "dev": "vite",
    "build": "tsc -b && vite build",
    "test": "vitest run",
    "lint": "eslint .",
    "typecheck": "tsc -p tsconfig.json --noEmit"
  }
}

Python

bash
python -m venv .venv
# Windows
.venv\Scripts\activate
# Unix
source .venv/bin/activate

pip install -r requirements.txt
pytest -q
ruff check .
mypy src
python
# pyproject 片段概念
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "-q"

Go

bash
go test ./...
go test -race ./...
go vet ./...
go build -o bin/api ./cmd/api
go
package main

import "fmt"

func main() {
	fmt.Println("ok")
}

Rust

bash
cargo test
cargo clippy -- -D warnings
cargo fmt --check
cargo build --release

Docker(本地服务)

bash
docker compose up -d
docker compose ps
docker compose logs -f --tail=100 api
docker compose exec db psql -U app -d app
docker compose down
yaml
# compose 片段
services:
  api:
    build: .
    ports:
      - "8080:8080"
    environment:
      DATABASE_URL: postgres://app:app@db:5432/app
  db:
    image: postgres:16-alpine

搜索与阅读代码

bash
# ripgrep
rg -n "TODO|FIXME" --glob '!node_modules'
rg -t ts "export async function"

# 只列文件
rg -l "ExportJob" src

HTTP 调试

bash
curl -sS -D- http://localhost:8080/healthz -o /dev/null
curl -sS -X POST http://localhost:8080/export-jobs \
  -H "content-type: application/json" \
  -d "{\"userId\":\"u_1\"}" | jq .

环境变量

bash
# .env 示例(勿提交真实密钥)
DATABASE_URL=postgres://user:pass@localhost:5432/app
OPENAI_API_KEY=sk-xxx

# 检查是否误提交
git grep -n "sk-" || true
rg "API_KEY|SECRET" -g'!.env*' || true
text
# .gitignore
.env
.env.*
!.env.example

表格:按场景选命令

场景命令
类型是否过tsc --noEmit
单测vitest run / pytest
格式prettier -c . / ruff format
容器是否健康docker compose ps
端口占用(Win)`netstat -ano

文件夹树 ← docs/ 目录 · Git · Cloudflare Pages