feat: 添加仓库迁移脚本

- 新增 migrate.sh 脚本用于将 Git 仓库迁移到新远程目标
- 脚本接受原始仓库 URL 和仓库名称作为参数
- 实现了从原始仓库克隆、清理元数据、重新初始化 Git 仓库
- 并配置新的远程目标,推送更改到新仓库
- 最后清理工作目录
This commit is contained in:
程广 2025-06-19 10:11:17 +08:00
parent de93986e6e
commit facb93cd90
1 changed files with 40 additions and 0 deletions

40
migrate.sh Normal file
View File

@ -0,0 +1,40 @@
#!/bin/bash
# Migrate Git repository to new remote target
# Parameters:
# $1 - Original repository URL (OURL)
# $2 - Repository name (RepoName)
# Returns:
# 0 - Success (all operations completed)
# !=0 - Failure (original git clone failed)
OURL=$1
RepoName=$2
TARGET=ssh://git@git.pyer.club:2222/SixMeta
# Clone original repository with shallow depth
git clone --depth 1 $OURL
# Check if clone succeeded
if [ $? -eq 0 ]; then
# Navigate to repo directory
cd $RepoName
# Clean up existing git metadata
rm -rf .git
# Reinitialize git repository with master branch
git init -b master
# Stage all files and create initial commit
git add .
git commit -m "migrate init"
# Configure new remote target and push changes
git remote add origin $TARGET/$RepoName.git
git push -u origin master
# Cleanup working directory
cd ..
rm -rf $RepoName
fi