git-sync: pull 失败时提示 pull.rebase=true 场景的绕过方法

This commit is contained in:
2026-09-14 18:55:00 +08:00
parent bd77c48829
commit d3802c3569
2 changed files with 8 additions and 0 deletions

View File

@@ -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