# 配置 Gitee 仓库:生成 SSH 密钥 + 建 .gitignore + 初始化提交 # 用法: powershell -NoProfile -ExecutionPolicy Bypass -File _build\setup_gitee.ps1 $ErrorActionPreference = "Continue" $git = "C:\Program Files\Git\bin\git.exe" $root = "C:\Users\shu\Desktop\deepseekagent\LanRemote" $sshDir = Join-Path $env:USERPROFILE ".ssh" Set-Location $root Write-Host "" Write-Host "===== 1. 生成 SSH 密钥(如果没有)=====" -ForegroundColor Cyan if (-not (Test-Path $sshDir)) { New-Item -ItemType Directory -Path $sshDir -Force | Out-Null } $keyPath = Join-Path $sshDir "id_ed25519_gitee" if (Test-Path $keyPath) { Write-Host " 密钥已存在: $keyPath" } else { & "$env:ProgramFiles\Git\usr\bin\ssh-keygen.exe" -t ed25519 -C "ykxmz-gitee" -f $keyPath -N '""' 2>&1 | Out-Null if (Test-Path $keyPath) { Write-Host " ✓ 已生成 $keyPath" } else { Write-Host " ✗ 生成失败" -ForegroundColor Red } } Write-Host "" Write-Host "===== 2. 配置 SSH(让 gitee.com 用这个密钥)=====" -ForegroundColor Cyan $sshConfig = Join-Path $sshDir "config" $marker = "# ykxmz-gitee" $existing = if (Test-Path $sshConfig) { Get-Content $sshConfig -Raw } else { "" } if ($existing -notmatch [regex]::Escape($marker)) { $block = @" $marker Host gitee.com HostName gitee.com User git IdentityFile $($keyPath -replace '\\','/') IdentitiesOnly yes StrictHostKeyChecking accept-new "@ Add-Content -Path $sshConfig -Value $block -Encoding UTF8 Write-Host " 已写入 $sshConfig" } else { Write-Host " SSH 配置已存在" } Write-Host "" Write-Host "===== 3. 建 .gitignore =====" -ForegroundColor Cyan $ignore = @' # ---- 构建产物(不提交,release 里单独发)---- /dist/ /dist_exe/ /_build/jc*/ /_build/out*/ /_build/*.png /_build/icon_source.png /_build/icon_preview.png /_build/admin_preview*.png /_build/ui_preview.png /_build/_unit.txt /_tests/out_java/ /_tests/out_app/ /_tests/received/ /_tests/_stubdata/ /_tests/shots/ # ---- Python ---- __pycache__/ *.py[cod] *.egg-info/ .venv/ venv/ # ---- 编辑器 / 系统 ---- .vscode/ .idea/ *.swp Thumbs.db desktop.ini .DS_Store # ---- 其它 ---- *.log *.tmp '@ Set-Content -Path (Join-Path $root ".gitignore") -Value $ignore -Encoding UTF8 Write-Host " 已写入 .gitignore" Write-Host "" Write-Host "===== 4. git 初始化 =====" -ForegroundColor Cyan if (-not (Test-Path (Join-Path $root ".git"))) { & $git init -q -b main 2>&1 | Out-Null Write-Host " ✓ git init" } else { Write-Host " 仓库已存在" } & $git config user.name "xmz7891" 2>&1 | Out-Null & $git config user.email "xmz7891@gitee.com" 2>&1 | Out-Null & $git config core.quotepath false 2>&1 | Out-Null & $git config core.autocrlf false 2>&1 | Out-Null Write-Host " ✓ 配置完成" Write-Host "" Write-Host "===== 5. 加 remote =====" -ForegroundColor Cyan $remotes = & $git remote 2>&1 if ($remotes -notcontains "origin") { & $git remote add origin "git@gitee.com:xmz7891/ykxmz.git" 2>&1 | Out-Null Write-Host " ✓ origin = git@gitee.com:xmz7891/ykxmz.git" } else { Write-Host " origin 已存在: $(& $git remote get-url origin)" } Write-Host "" Write-Host "===== 6. 待提交文件统计 =====" -ForegroundColor Cyan & $git add -A 2>&1 | Out-Null $staged = (& $git diff --cached --name-only 2>&1) Write-Host " 暂存文件数: $($staged.Count)" $size = 0 foreach ($f in $staged) { $p = Join-Path $root $f if (Test-Path $p -PathType Leaf) { $size += (Get-Item $p).Length } } Write-Host " 总体积: $([math]::Round($size/1MB,2)) MB" Write-Host "" Write-Host "===== 7. 你的公钥(要加到 Gitee)=====" -ForegroundColor Yellow if (Test-Path "$keyPath.pub") { Get-Content "$keyPath.pub" | ForEach-Object { Write-Host " $_" -ForegroundColor White } }