code-sync
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode Sync
代码同步
Batch sync all git repos under — push (end-of-day) or pull (start-of-day).
~/code批量同步目录下的所有Git仓库——下班时推送(push)或上班时拉取(pull)。
~/codePrerequisites
前置条件
| Tool | Type | Required | Install |
|---|---|---|---|
| git | cli | Yes | |
| git-workflow | skill | No | Included in |
Do NOT proactively verify these tools on skill load. If a command fails due to a missing tool, directly guide the user through installation and configuration step by step.
| 工具 | 类型 | 是否必需 | 安装方式 |
|---|---|---|---|
| git | 命令行工具 | 是 | |
| git-workflow | 技能 | 否 | 包含在 |
请勿在技能加载时主动验证这些工具。如果因缺少工具导致命令失败,请直接逐步引导用户完成安装和配置。
Mode Selection
模式选择
| User says | Mode |
|---|---|
| 「下班同步」or "push" | Push |
| 「上班更新」or "pull" | Pull |
| 「同步代码」「code-sync」 | Ask user |
| 用户指令 | 模式 |
|---|---|
| 「下班同步」或 "push" | 推送(Push) |
| 「上班更新」或 "pull" | 拉取(Pull) |
| 「同步代码」「code-sync」 | 询问用户 |
Workflow (shared by both modes)
工作流程(两种模式通用)
- Scan → 2. Categorize → 3. Batch action (auto, no confirmation) → 4. Handle exceptions (interactive) → 5. Summary
If all repos are up-to-date, report that and stop.
- 扫描 → 2. 分类 → 3. 批量操作(自动执行,无需确认) → 4. 异常处理(交互式) → 5. 汇总
如果所有仓库均为最新状态,则直接报告并终止流程。
Scan
扫描
bash
bash scripts/scan.sh # Push: local data only
bash scripts/scan.sh --fetch # Pull: fetch remote first (10s timeout/repo)Output: JSON array with fields , , , , , , , , , and (only on failure).
pathnamebranchremoteremote_urldirty_counthas_upstreamaheadbehindfetch_error--fetchbash
bash scripts/scan.sh # 推送模式:仅扫描本地数据
bash scripts/scan.sh --fetch # 拉取模式:先拉取远程数据(每个仓库超时10秒)输出:JSON数组,包含字段、、、、、、、、,以及(仅在失败时出现)。
pathnamebranchremoteremote_urldirty_counthas_upstreamaheadbehindfetch_error--fetchCategorize
分类
Push mode:
| Category | Condition | Action |
|---|---|---|
| up-to-date | | Report |
| needs-push | | Auto |
| dirty | | Interactive |
| no-upstream | | Ask user |
Pull mode:
| Category | Condition | Action |
|---|---|---|
| up-to-date | | Report |
| needs-pull | | Auto |
| dirty+behind | | Interactive |
| fetch-error | | Report, skip |
推送模式:
| 分类 | 条件 | 操作 |
|---|---|---|
| 已同步 | | 报告状态 |
| 需要推送 | | 自动执行 |
| 脏仓库 | | 交互式处理 |
| 无上游分支 | | 询问用户 |
拉取模式:
| 分类 | 条件 | 操作 |
|---|---|---|
| 已同步 | | 报告状态 |
| 需要拉取 | | 自动执行 |
| 脏仓库+落后远程 | | 交互式处理 |
| 拉取失败 | | 报告并跳过 |
Exception Handling
异常处理
| Situation | Steps |
|---|---|
| Dirty repo (push) | |
| No upstream (push) | Report → ask: set upstream and push ( |
| ff-only fails (pull) | |
| Dirty + behind (pull) | Report both issues → ask: stash and pull (stash, pull --ff-only, pop), or skip |
| 场景 | 处理步骤 |
|---|---|
| 脏仓库(推送模式) | 执行 |
| 无上游分支(推送模式) | 报告状态 → 询问:设置上游并推送( |
| ff-only执行失败(拉取模式) | 执行 |
| 脏仓库+落后远程(拉取模式) | 报告两个问题 → 询问:暂存并拉取(暂存、拉取--ff-only、恢复暂存),或跳过 |
Summary
汇总
Group repos by outcome after all operations complete:
text
undefined所有操作完成后,按结果分组汇总仓库状态:
text
undefined{Push|Pull} Summary
{推送|拉取}汇总
{Pushed|Updated} (N):
- repo-name (branch, N commits) Already up-to-date (N):
- repo-a, repo-b, ... Resolved (N):
- repo-c: action taken Skipped (N):
- repo-d: reason
undefined{已推送|已更新} (N个):
- 仓库名称 (分支, N次提交) 已同步 (N个):
- 仓库a, 仓库b, ... 已解决 (N个):
- 仓库c: 执行的操作 已跳过 (N个):
- 仓库d: 跳过原因
undefinedCommon Issues
常见问题
| Issue | Fix |
|---|---|
| Check |
| Check network, SSH keys |
| ff-only fails | Rebase or merge manually |
| Push rejected | Pull first, then push |
| 问题 | 解决方法 |
|---|---|
| 检查 |
| 检查网络连接、SSH密钥 |
| ff-only执行失败 | 手动执行变基或合并操作 |
| 推送被拒绝 | 先拉取远程代码,再重新推送 |