根据SF官方文档的介绍:
https://sourceforge.net/p/forge/documentation/CVS/
把CVS项目转换到git需要用cvs2svn项目中的cvs2git,但实际上这个需要Python2 而自己的MacBook上已经都是python3了:
会遇到错误信息:
brew install cvs2svn
Warning: No available formula with the name "cvs2svn".
==> Searching for similarly named formulae and casks...
Error: No formulae or casks found for cvs2svn.
install cvs2svn Defaulting to user installation because normal site-packages is not writeable ERROR: Could not find a version that satisfies the requirement cvs2svn (from versions: none) ERROR: No matching distribution found for cvs2svn好在找到了cvs-fast-export项目,用Claude重新生成了迁移脚本:
错误: cvs2git 无法运行
请检查 Python 3 是否已安装: python3 --versionERROR: cvs2git requires Python 2, version 2.4 or later; it does not
work with Python 3. You are currently using version 3.14.2.
Please restart cvs2git using a different version of the Python
interpreter. Visit http://www.python.org or consult your local system
administrator if you need help.
我的工作目录是/Users/chedong/CodeWork
#!/bin/bash # CVS to Git 转换脚本 - phpunixman 项目 # 使用 cvs-fast-export 工具(现代替代方案,不需要 Python 2) # 工作目录: /Users/chedong/CodeWorkset -e # 遇到错误立即退出
# 配置变量
WORK_DIR="/Users/chedong/CodeWork"
PROJECT_NAME="phpunixman"
CVS_BACKUP_URL="https://sourceforge.net/code-snapshots/cvs/p/ph/${PROJECT_NAME}.zip"# 颜色输出
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Colorecho -e "${BLUE}=== phpunixman CVS to Git 转换开始(使用 cvs-fast-export)===${NC}"
# 检查 cvs-fast-export 是否已安装
if ! command -v cvs-fast-export &> /dev/null; then
echo -e "${YELLOW}未找到 cvs-fast-export,正在安装...${NC}"
brew install cvs-fast-export
echo -e "${GREEN}cvs-fast-export 已安装${NC}"
fi# 检查 CVS 是否已安装
if ! command -v cvs &> /dev/null; then
echo -e "${YELLOW}未找到 cvs,正在安装...${NC}"
brew install cvs
echo -e "${GREEN}cvs 已安装${NC}"
fi# 进入工作目录
cd "$WORK_DIR"
echo -e "${GREEN}[1/9] 进入工作目录: $WORK_DIR${NC}"# 下载 CVS 仓库备份
echo -e "${GREEN}[2/9] 下载 CVS 仓库备份...${NC}"
if [ ! -f "${PROJECT_NAME}.zip" ]; then
curl -L -o "${PROJECT_NAME}.zip" "$CVS_BACKUP_URL"
echo "CVS 备份已下载"
else
echo "CVS 备份文件已存在,跳过下载"
fi# 解压 CVS 备份
echo -e "${GREEN}[3/9] 解压 CVS 备份...${NC}"
if [ ! -d "${PROJECT_NAME}" ]; then
unzip -q "${PROJECT_NAME}.zip"
echo "CVS 备份已解压"
else
echo "CVS 备份目录已存在,跳过解压"
fi# 创建 author mapping 文件(可选)
echo -e "${GREEN}[4/9] 创建作者映射文件...${NC}"
cat > author-map.txt << 'EOF'
# CVS 用户名到 Git 作者的映射
# 格式: cvs_username=Full Name
chedong=Che Dong
EOF
echo "作者映射文件已创建(author-map.txt),请根据需要编辑"# 查找所有 CVS 文件
echo -e "${GREEN}[5/9] 分析 CVS 仓库结构...${NC}"
CVS_FILES=$(find "${PROJECT_NAME}" -name '*,v' | wc -l | tr -d ' ')
echo "找到 ${CVS_FILES} 个 CVS 文件"# 创建新的 Git 仓库目录
echo -e "${GREEN}[6/9] 创建新的 Git 仓库...${NC}"
GIT_REPO="${PROJECT_NAME}-git"
if [ -d "$GIT_REPO" ]; then
echo -e "${YELLOW}警告: $GIT_REPO 已存在,将被删除${NC}"
read -p "是否继续?(y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "操作已取消"
exit 1
fi
rm -rf "$GIT_REPO"
fimkdir -p "$GIT_REPO"
cd "$GIT_REPO"
git init
cd ..# 使用 cvs-fast-export 转换
echo -e "${GREEN}[7/9] 转换 CVS 到 Git 格式(这可能需要几分钟)...${NC}"
cd "${PROJECT_NAME}"# 执行转换
find . -name '*,v' -print | cvs-fast-export -A ../author-map.txt > ../cvs-export.ficd ..
# 导入到 Git 仓库
echo -e "${GREEN}[8/9] 导入数据到 Git 仓库...${NC}"
cd "$GIT_REPO"
git fast-import < ../cvs-export.fi# 检出主分支
git checkout master 2>/dev/null || git checkout main 2>/dev/null || true# 显示转换结果
echo -e "${GREEN}[9/9] 验证转换结果...${NC}"
echo ""
echo "提交数量: $(git rev-list --all --count)"
echo "分支列表:"
git branch -a
echo ""
echo "最近的提交:"
git log --oneline -5 || echo "暂无提交"cd ..
echo -e "${BLUE}=== 本地转换完成 ===${NC}"
echo ""
echo "转换后的 Git 仓库位于: $WORK_DIR/$GIT_REPO"
echo ""
echo "接下来的步骤:"
echo "1. 验证转换结果:"
echo " cd $WORK_DIR/$GIT_REPO"
echo " git log --all --graph --oneline"
echo ""
echo "2. 推送到 SourceForge(需要先配置 SSH 密钥):"
echo " cd $WORK_DIR/$GIT_REPO"
echo " git remote add origin ssh://chedong@git.code.sf.net/p/${PROJECT_NAME}/code"
echo " git push origin --all"
echo " git push origin --tags"
echo ""
echo "3. 清理临时文件(在确认无误后):"
echo " cd $WORK_DIR"
echo " rm -f ${PROJECT_NAME}.zip"
echo " rm -f cvs-export.fi"
echo " rm -f author-map.txt"
echo " rm -rf ${PROJECT_NAME}"
导出到工作目录
git clone ssh://chedong@git.code.sf.net/p/phpunixman/code.git phpunixman作者:车东 发表于:2026-01-07 14:01 最后更新于:2026-01-07 15:01
cd phpunixman
版权声明:可以转载,转载时请务必以超链接形式标明文章 迁移SF上的项目:从cvs到git 的原始出处和作者信息及本版权声明。
http://www.chedong.com/blog/archives/001508.html
