工具链备忘(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 HEADNode / 前端
bash
node -v
npm ci
npm run build
npm run test -- --watch=false
# 为什么装了这个包
npm ls lodash
pnpm why axiospackage.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 srcpython
# pyproject 片段概念
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "-q"Go
bash
go test ./...
go test -race ./...
go vet ./...
go build -o bin/api ./cmd/apigo
package main
import "fmt"
func main() {
fmt.Println("ok")
}Rust
bash
cargo test
cargo clippy -- -D warnings
cargo fmt --check
cargo build --releaseDocker(本地服务)
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 downyaml
# 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" srcHTTP 调试
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*' || truetext
# .gitignore
.env
.env.*
!.env.example表格:按场景选命令
| 场景 | 命令 |
|---|---|
| 类型是否过 | tsc --noEmit |
| 单测 | vitest run / pytest |
| 格式 | prettier -c . / ruff format |
| 容器是否健康 | docker compose ps |
| 端口占用(Win) | `netstat -ano |