Git 踩坑记录

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

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

方法 1:临时改名

bash 复制代码
git mv FolderName tempname
git commit -m "临时改名"
git push

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

方法 2:强制更新

bash 复制代码
git config core.ignorecase false
git add -A
git commit -m "修正大小写"
git push

清除缓存(必要时)

bash 复制代码
git rm -r --cached FolderName
git add foldername
git commit -m "修正大小写"
git push

2 中文路径异常

注意:不考虑 SVN 分支

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

bash 复制代码
git config --global core.quotepath false

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

3 SVN 仓库迁移到 Git

bash 复制代码
# 初始化 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
txt 复制代码
# authors.txt 示例
yaoxin = BeyondXinXin <779354187@qq.com>
VisualSVN Server = BeyondXinXin <779354187@nt.com>

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

4 批量替换作者

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

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

bash 复制代码
# 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
)
相关推荐
驭渊的小故事7 小时前
linux 基础命令 + git 仓库创建和配置命令
linux·git
行者-全栈开发12 小时前
华为云码道 CodeArts 实测:让 AI 用 Rust 写一个 Git 仓库健康度体检台「仓衡」
git·rust·tauri·桌面应用·ai 编程·华为云码道·codearts 代码智能体
挖掘狂人2 天前
Git 从 0 到 1:用一个小项目走完 add / commit / reset / merge / rebase / push
git·后端·github
codigger3 天前
Git 三区域模型:把 add、commit、reset、merge 一次讲透
git·github·编程·编程语言
水饺编程3 天前
第1章:开发环境搭建,在 Windows 中安装 Git
linux·c语言·汇编·git·ubuntu
idanzk3 天前
Git 推送 GitHub 报 SSL_READ /src refspec main 不匹配 完整踩坑记录
git·github·ssl
星恒随风3 天前
Linux开发工具详解(二):Git版本控制、GitHub协作与GDB调试实战
linux·笔记·git·学习·github
寺中人3 天前
Xshell 完全入门指南:从安装到实战,远程连接+文件传输+会话管理全拆解
git·ssh·github·php·远程连接·xshell·运维工具
酬谢神明则必安3 天前
git学习记录01
linux·git·学习
lingchen19063 天前
版本控制 Git源代码项目管理
git