#!/bin/bash echo "=== 修复 Git 远程仓库配置 ===" echo "" echo "当前远程仓库配置:" git remote -v echo "" # 获取当前远程 URL CURRENT_URL=$(git config --get remote.origin.url) echo "当前 URL: $CURRENT_URL" echo "" # 检查是否是 Hugging Face Spaces if echo "$CURRENT_URL" | grep -q "huggingface\|hf.co"; then echo "检测到 Hugging Face 仓库" # 尝试提取用户名和空间名 if echo "$CURRENT_URL" | grep -q "spaces/"; then SPACE_PATH=$(echo "$CURRENT_URL" | sed -E 's|.*spaces/([^/]+/[^/]+).*|\1|') echo "检测到的空间路径: $SPACE_PATH" # 构建正确的 SSH URL NEW_URL="git@hf.co:spaces/$SPACE_PATH" echo "" echo "建议的 SSH URL: $NEW_URL" echo "" read -p "是否更新为: $NEW_URL? (y/n): " confirm if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then git remote set-url origin "$NEW_URL" echo "✓ 已更新远程 URL" echo "" echo "新的远程配置:" git remote -v echo "" echo "现在可以尝试: git push" fi else echo "无法自动识别空间路径" echo "" echo "请手动设置:" echo " git remote set-url origin git@hf.co:spaces/YOUR_USERNAME/YOUR_SPACE_NAME" fi else echo "未检测到 Hugging Face 仓库" echo "" echo "如果是 Hugging Face Spaces,请设置:" echo " git remote set-url origin git@hf.co:spaces/YOUR_USERNAME/YOUR_SPACE_NAME" echo "" echo "或者如果是 Hugging Face 模型仓库:" echo " git remote set-url origin git@hf.co:YOUR_USERNAME/YOUR_MODEL_NAME" fi