返回顶部
b

batch-git-url-replace批量替换Git地址

|

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
160
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

batch-git-url-replace

批量替换 Git 远程地址

输入参数

执行前必须从用户处获取以下参数:

  • - scanDir:扫描目录路径(如 D:\ 或 /home/user/projects)
  • oldUrl:旧 Git 服务器地址
  • newUrl:新 Git 服务器地址

执行步骤

Windows 系统

使用 PowerShell 执行以下命令(将参数替换为用户提供的实际值):

powershell
$scanDir =
$oldUrl =
$newUrl =

Write-Host 开始扫描 $scanDir 下的所有 .git/config 文件... -ForegroundColor Cyan
Write-Host 目标:将 $oldUrl 替换为 $newUrl -ForegroundColor Cyan
Write-Host ----------------------------------------

$gitDirs = Get-ChildItem -Path $scanDir -Recurse -Directory -Filter .git -Force -ErrorAction SilentlyContinue

$countSuccess = 0
$countSkip = 0

foreach ($gitDir in $gitDirs) {
$configPath = Join-Path $gitDir.FullName config
if (Test-Path $configPath) {
try {
$content = Get-Content -Path $configPath -Raw -Encoding UTF8
if ($content -like $oldUrl) {
$newContent = $content -replace [regex]::Escape($oldUrl), $newUrl
Set-Content -Path $configPath -Value $newContent -Encoding UTF8 -NoNewline
Write-Host [已修改] $configPath -ForegroundColor Green
$countSuccess++
} else {
$countSkip++
}
} catch {
Write-Host [错误] 无法处理 $configPath : $_ -ForegroundColor Red
}
}
}

Write-Host ----------------------------------------
Write-Host 处理完成!成功: $countSuccess, 跳过: $countSkip -ForegroundColor Yellow

Linux 系统

使用 Bash 执行以下命令:

bash
SCAN_DIR=
OLD_URL=
NEW_URL=

echo 开始扫描 $SCAN_DIR 下的所有 .git/config 文件...
echo 目标:将 $OLDURL 替换为 $NEWURL
echo ----------------------------------------

count_success=0
count_skip=0

while IFS= read -r gitdir; do
config=$gitdir/config
if [ -f $config ] && grep -q $OLD_URL $config 2>/dev/null; then
sed -i s|${OLDURL}|${NEWURL}|g $config
echo [已修改] $config
((count_success++))
else
((count_skip++))
fi
done < <(find $SCAN_DIR -name .git -type d 2>/dev/null)

echo ----------------------------------------
echo 处理完成!成功: $countsuccess, 跳过: $countskip

执行后

建议用户进入某个项目目录运行 git remote -v 验证是否生效。

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 batch-git-url-replace-1776201068 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 batch-git-url-replace-1776201068 技能

通过命令行安装

skillhub install batch-git-url-replace-1776201068

下载

⬇ 下载 batch-git-url-replace v1.0.0(免费)

文件大小: 2 KB | 发布时间: 2026-4-17 14:11

v1.0.0 最新 2026-4-17 14:11
Initial release of batch-git-url-replace

- Supports batch replacement of remote URLs for all Git repositories under a specified directory.
- Provides step-by-step instructions and ready-to-use scripts for both Windows (PowerShell) and Linux (Bash).
- Requires users to input scan directory, old URL, and new URL for operation.
- Logs modified and skipped repositories and summarizes the results.
- Recommends validating remote URL changes with git remote -v after execution.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部