跳转至

踩坑记录

1 文件/目录大小写问题(Windows/macOS)

Git 默认对大小写不敏感,修改文件夹大小写可能无法在远程仓库更新。

方法 1:临时改名

git mv FolderName tempname
git commit -m "临时改名"
git push

git mv tempname foldername
git commit -m "改回目标大小写"
git push

方法 2:强制更新

git config core.ignorecase false
git add -A
git commit -m "修正大小写"
git push

清除缓存(必要时)

git rm -r --cached FolderName
git add foldername
git commit -m "修正大小写"
git push

2 中文路径异常

注意:不考虑 SVN 分支

Git 输出中文路径可能乱码,解决方法:

git config --global core.quotepath false

作用:禁用输出路径的引号和转义,使 git status/git log 更易读。

3 SVN 仓库迁移到 Git

# 初始化 git-svn 仓库
git svn init https://example.com/svn/repo

# 拉取指定版本及作者对应
git svn fetch -A authors.txt -r 0:100 

# 合并 svn 分支到 master
git merge remotes/git-svn

# 回退至指定版本(可选)
git svn reset -r 4000
# authors.txt 示例
yaoxin = BeyondXinXin <779354187@qq.com>
VisualSVN Server = BeyondXinXin <779354187@nt.com>

注意:需要完整作者映射表

4 批量替换作者

重写历史时统一作者信息,适合迁移或整理历史仓库。

注意:执行前一定要备份仓库,否则历史被重写无法恢复。

# 1. 安装工具
python install git-filter-repo

# 2. 将可执行程序放到 Git 执行目录(Windows 示例)
# C:\Users\HP\AppData\Roaming\Python\Python312\Scripts\git-filter-repo.exe
# C:\Program Files\Git\bin\git-filter-repo.exe

# 3. 创建映射文件 mailmap.txt
# 内容示例:
# BeyondXin <779354187@qq.com>

# 4. 执行替换(提前备份仓库,如果不用 --force 需要先 clone 新仓库)
git filter-repo --mailmap ../mailmap.txt --force

# 5. 清除引用标记
:: delete_replaces.bat
@echo off
for /f "delims=" %%i in ('git replace -l') do (
    git replace -d %%i
)