diff --git a/git-sync/SKILL.md b/git-sync/SKILL.md index 9e034f1..633dd6c 100644 --- a/git-sync/SKILL.md +++ b/git-sync/SKILL.md @@ -75,4 +75,5 @@ metadata: - sync 检测到 unmerged paths(`git ls-files -u`)会直接拒绝提交,先解决冲突 - `resolve remote`(`git reset --hard`)与 `resolve local`(force push)都会丢内容,必须先经 clarify 拿到用户明确选择,脚本侧再加 `GIT_SYNC_CONFIRM=yes` - push 失败(码 3)通常是 pull 后又有人推了东西:重新 `status`,再走分叉决策 +- **`pull.rebase=true` 的仓库**(本机 nexus 即如此):有未暂存改动时 ff-only pull 必失败报 "cannot pull with rebase",哪怕与远端无文件重叠——先用 `git diff --name-only HEAD origin/main` 确认无重叠,再 `git -c pull.rebase=false pull --ff-only`,不必惊动用户。脚本遇此会自动打印 hint - 脚本由其他技能/agent 复用时同样适用,别只当本技能专用 \ No newline at end of file diff --git a/git-sync/scripts/git-sync.sh b/git-sync/scripts/git-sync.sh index f3de971..ac8df95 100755 --- a/git-sync/scripts/git-sync.sh +++ b/git-sync/scripts/git-sync.sh @@ -58,6 +58,11 @@ status_cmd() { exit 0 } +rebase_hint() { + [ "$(git config pull.rebase 2>/dev/null || true)" = "true" ] \ + && echo " hint: 本仓库 pull.rebase=true — 若本地改动与远端无文件重叠(git diff --name-only HEAD origin/main 为空交集),可用: git -c pull.rebase=false pull --ff-only" >&2 +} + pull_ff() { local AHEAD BEHIND read -r AHEAD BEHIND < <(ahead_behind) @@ -69,6 +74,7 @@ pull_ff() { echo "==> git pull --ff-only origin $BRANCH" if ! git pull --ff-only origin "$BRANCH" 2>&1; then echo "CONFLICT: pull 失败 — 本地未提交改动与远端更新冲突,或需要 merge" >&2 + rebase_hint exit 4 fi git log -1 --format='pulled: %h %s' @@ -97,6 +103,7 @@ sync_cmd() { echo "==> pull --ff-only origin $BRANCH" if ! git pull --ff-only origin "$BRANCH" 2>&1; then echo "CONFLICT: pull 失败 — 本地未提交改动与远端更新冲突" >&2 + rebase_hint exit 4 fi fi