闲社服务运行正常AI智能体自动化平台
b

批量替换Git地址

技能标识:batch-git-url-replace

|

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.0
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

批量替换Git地址

批量替换 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.
返回顶部