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
)
相关推荐
一只积极向上的小咸鱼11 小时前
嵌套 Git 仓库 / gitlink / submodule 问题总结
大数据·git·elasticsearch
LuDvei11 小时前
git拉取报错问题
git
程序猿多布12 小时前
Fork操作笔记
git·fork
荪荪12 小时前
在本地建立git仓库
git
OYangxf13 小时前
Git Rollback, Reset and Restore的使用
git
AIMath~13 小时前
git管理代码仓库的工具
git
techdashen18 小时前
为 Agent 重新设计的 Git:Cloudflare Artifacts 是什么,怎么工作的
git
赖在沙发上的熊18 小时前
Git多仓库协作中和并冲突问题:“不相关历史合并”+“问跟踪文件冲突”
git
风若飞19 小时前
▎ 适用于完全没有 Git 经验的新手
git
时空自由民.21 小时前
git rebase简介
git