Files
users/scripts/push-to-github.sh

46 lines
1.5 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 以本地为准:上传本地全部文件,强制替换 GitHub 上 v0/fnvtk-5efaab9c不拉取、不改本地
# 在终端执行: bash scripts/push-to-github.sh
set -e
cd "$(dirname "$0")/.."
# 从卡若AI 账号与API索引 提取 GitHub Token
TOKEN_FILE="$HOME/Documents/个人/卡若AI/01_卡资/_团队成员/金盾/账号密码与资料管理/账号与API索引.md"
if [ -f "$TOKEN_FILE" ]; then
GITHUB_TOKEN=$(grep "Token.*ghp_" "$TOKEN_FILE" | sed -E "s/.*\`([^\`]+)\`.*/\1/")
fi
if [ -z "$GITHUB_TOKEN" ]; then
echo "未找到 GitHub Token使用 origin 推送(需已配置凭据)"
PUSH_URL="origin"
else
PUSH_URL="https://${GITHUB_TOKEN}@github.com/fnvtk/users.git"
echo "已从卡若AI 读取 Token"
fi
echo "=== 1. 当前状态(本地分支) ==="
git status
echo ""
echo "=== 2. 添加本地全部文件 ==="
git add -A
git status
echo ""
echo "=== 3. 提交(有变更才提交) ==="
if git diff --cached --quiet; then
echo "工作区无新变更,将直接以当前提交强制覆盖远程"
else
git commit -m "chore: 以本地为准,上传全部并替换 GitHub"
echo "提交完成"
fi
echo ""
echo "=== 4. 强制推送到 GitHub覆盖 v0/fnvtk-5efaab9c ==="
# 当前分支HEAD覆盖远程 v0/fnvtk-5efaab9c重叠处一律以本地为准
git push --force "$PUSH_URL" HEAD:v0/fnvtk-5efaab9c
echo ""
echo "=== 完成 ==="
echo "GitHub 已与本地一致: https://github.com/fnvtk/users/tree/v0/fnvtk-5efaab9c"