From facb93cd90a3da62d9e95c7e67d9f449e05450f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=B9=BF?= Date: Thu, 19 Jun 2025 10:11:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 migrate.sh 脚本用于将 Git 仓库迁移到新远程目标 - 脚本接受原始仓库 URL 和仓库名称作为参数 - 实现了从原始仓库克隆、清理元数据、重新初始化 Git 仓库 - 并配置新的远程目标,推送更改到新仓库 - 最后清理工作目录 --- migrate.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 migrate.sh diff --git a/migrate.sh b/migrate.sh new file mode 100644 index 0000000..044880b --- /dev/null +++ b/migrate.sh @@ -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 \ No newline at end of file