docs: 记录中文 commit message 乱码修复经验(提交历史重写为 2c90205/4b3ea03/b11bea1)

This commit is contained in:
2026-08-23 11:39:23 +08:00
parent b11bea1962
commit 8df2f002d2
4 changed files with 12 additions and 1 deletions
+7
View File
@@ -201,3 +201,10 @@
- **新增根目录 `开发进度存档`(无扩展名)**:作为跨会话上下文恢复入口,含目录结构/快速启动/打包手册(含所有坑)/代码结构地图/功能清单/待办/Git 信息/踩坑实录表。
- MEMORY.md 更新:顶部加「换环境先读 `开发进度存档`」指引;文档三件套说明;打包章节更新(128.9MB、build/icon.ico、SafeDelete 坑)。
- 目的:用户重装 CodeBuddy/换文件夹路径后,新会话读 `开发进度存档` 即可省积分快速恢复上下文。
## 2026-08-23 修复中文 commit message 双编码乱码
- **现象**`git log` 提交信息显示乱码(如 `椤圭洰闇€姹傚崌绾?`),经字节级验证(cmd 重定向 + node 读 hex)确认为**存储层乱码**PowerShell/cmd 把中文 `-m` 参数按 GBK 编码传给 git,git 按 UTF-8 存储 → 双编码。
- **修复**Node 脚本(`fix-msgs.js`,用完已删)用 `git cat-file commit` 读原对象 → 保留 headertree/parent/author/committer/时间戳)→ 仅替换 message → `git hash-object -t commit -w --stdin` 重建 → `git update-ref`。新 hash`2c90205`init/`4b3ea03`build/`b11bea1`docs)。已 `git push --force-with-lease` 强推(用户授权),`69d592b...b11bea1 (forced update)`,远程一致、工作区干净。
- **以后约定**:提交信息用 `git commit -F <utf8消息文件>`write_to_file 生成的 UTF-8 文件),**禁用 `git commit -m "中文"`**。
- **执行环境备注**execute_command 实际走 cmd`2>$null` 会被当作重定向生成 `$null` 文件(需手动删);`;` 不分割 cmd 命令;`[Console]::OutputEncoding=UTF8` 对 git 输出无效,验证用 `git log > file` 后 read_file 工具读。
+1
View File
@@ -12,6 +12,7 @@
- 依赖固定 `electron-vite@5 vite@7 @vitejs/plugin-react@5`(避免 vite8 与 electron-vite peer 冲突);Electron ^43。
- 命令:`npm run dev` / `npm run build` / `npm start`preview/ `npm run typecheck`
- **中文路径 PowerShell 坑**:参数含中文路径(`c:/Users/范先生/...`)会乱码导致 cd 失败,命令一律用相对路径。
- **⚠️ 中文 commit message 坑(2026-08-23 修复)**`git commit -m "中文"` 在 PowerShell/cmd 下会按 GBK 传参、git 按 UTF-8 存储 → **提交信息双编码乱码**。已用 Node 脚本 + `git hash-object` 保真重写 3 条历史并 force push(新 hash2c90205/4b3ea03/b11bea1)。**以后提交一律用 `git commit -F <utf8消息文件>`**write_to_file 写 UTF-8 文件再 -F),或提交信息用英文。
- 后台启动 dev`cd SmartAgriCenter; Start-Process npm.cmd -ArgumentList 'run','dev' -RedirectStandardOutput 'dev.log' -RedirectStandardError 'dev-err.log'`(必须 npm.cmd)。
- Electron 二进制缺失时:先 `$env:ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"``node node_modules/electron/install.js`
- dev.log / dev-err.log 留在 SmartAgriCenter 根目录,受 SafeDelete 保护,无害。
+1
View File
@@ -0,0 +1 @@
docs: 记录中文 commit message 乱码修复经验(提交历史重写为 2c90205/4b3ea03/b11bea1
+3 -1
View File
@@ -129,7 +129,8 @@ Get-CimInstance Win32_Process | Where CommandLine -like '*SmartAgriCenter*' | Fo
- 远程:`https://github.bbitcn.net/fanhongcai/DataViewCenter.git`
- **远程名是 `DataViewCenter`,不是 `origin`**`main` 已设上游跟踪 → 直接 `git push`
- 提交历史`68810be`init 全量)→ `682962e`(打包瘦身
- 提交历史2026-08-23 重写乱码信息后):`2c90205`init 全量)→ `4b3ea03`(打包瘦身)→ `b11bea1`(文档存档
- **⚠️ 提交信息防乱码**`git commit -m "中文"` 在本机会双编码乱码(GBK→UTF-8),**必须用 `git commit -F <utf8消息文件>`**
- `.gitignore` 忽略:node_modules / out / dist / release / 日志 / IDE
- `.codebuddy/memory/` 随仓库备份(跨会话记忆)
@@ -138,6 +139,7 @@ Get-CimInstance Win32_Process | Where CommandLine -like '*SmartAgriCenter*' | Fo
| 坑 | 解法 |
|---|---|
| PowerShell 中文路径乱码 | 命令用相对路径;先 cd 再执行;避免 `git -C`/直接写中文文件名 |
| **中文 commit message 乱码** | `git commit -m "中文"` 会双编码乱码(GBK→UTF-8)。**改用 `git commit -F <utf8消息文件>`**;已损坏的历史可用 Node 脚本 + `git hash-object -t commit -w` 保真重写(保留 author/committer/时间戳)再 force push |
| `npm run dist` 卡死/文件占用 | 挂死的 node/electron-builder 进程未退出 → 先杀进程再删 release(§4) |
| CodeBuddy 删除守卫拦截批量删除 | 用 `[System.IO.Directory]::Delete(dir,$true)` 或 `cmd /c "rd /s /q <dir>"` |
| electron 二进制缺失("Electron failed to install correctly" | `node node_modules/electron/install.js`;网络受限先 `$env:ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"` |