3.1 KiB
3.1 KiB
name: git-push-dlp description: 在 DLP 透明加密保护区(如 E:\WorkSpace\)内执行 git push。保护区内直接 git push 必现 "fatal: not a git repository (or any of the parent directories): .git"(退出码 128),但其他 git 命令(status / fetch / commit / pull)全部正常。触发条件:"git push 失败"、"push 报 not a git repository"、"DLP push"、"git_push_dlp",或遇到上述 128 错误时。
git-push-dlp — DLP 保护区内 git push
问题背景
本机装有透明加密系统(DLP),E:\WorkSpace\ 属于保护区。在保护区内执行
git push 会必现:
fatal: not a git repository (or any of the parent directories): .git
退出码 128。这是 DLP 驱动对 push 进程访问模式的拦截,不是仓库损坏——
不要修仓库、不要重装 git。同一个 .git 复制到保护区外 push 立刻正常;
对保护区内的 .git 原地解密无效(写回会被驱动重新加密)。
原理
xcopy .git到%TEMP%\git_push_dlp\<repo>-<random>\(保护区外,授权进程 读出明文,写出不再加密)。默认通过/EXCLUDE排除.git\lfs(LFS 对象 缓存,动辄数 GB,普通提交 push 不需要)。- 在 stage 副本里执行
git push。 - 回到原仓库
git fetch同步远程跟踪引用,然后删除 stage。
使用方法
脚本位置:<skill_dir>\scripts\git_push_dlp.bat,在仓库根目录执行:
cmd /c <skill_dir>\scripts\git_push_dlp.bat = git push origin HEAD
cmd /c <skill_dir>\scripts\git_push_dlp.bat origin main = git push origin main
cmd /c <skill_dir>\scripts\git_push_dlp.bat upstream main:main
如果本次 push 包含新增 / 变更的 LFS 文件(.pt / .onnx / .zip 等,见
.gitattributes),先设置环境变量再运行,恢复全量复制 .git\lfs:
set GIT_PUSH_DLP_WITH_LFS=1
排障
[ERROR] xcopy .git failed. Insufficient disk space:TEMP 所在盘空间不足。 先清理%TEMP%\git_push_dlp\下历史失败残留的TestHub-*目录(脚本在 xcopy 失败时不会自动清理)。仍不足时确认是否误设了GIT_PUSH_DLP_WITH_LFS(全量 lfs 可能超过盘符剩余空间)。- stage 在 E: 盘也报 128:整个 E: 盘都在 DLP 拦截范围内,stage 必须落在
C:(
%TEMP%默认位置),不要把TEMP指到 E:。 - 注释行被当成命令执行 / 解析错乱:bat 被写成了 LF 行尾或混入了 UTF-8 中文注释,见下面维护注意。
维护注意(修改 scripts/git_push_dlp.bat 时必读)
- 文件必须保持 CRLF 行尾;编辑工具若写成 LF,cmd 会把注释行当命令执行。
修正方法:
unix2dos <file>。 - 注释(
rem)保持英文。UTF-8 无 BOM 的中文注释会被 cmd 批解析器误解析。 - 括号代码块内引用本块内
set的变量要用延迟扩展!VAR!而不是%VAR%。
备注
全局副本 C:\Users\p40000043244\bin\git_push_dlp.bat(已加入用户 PATH)仍然
可用,供其他保护区仓库使用;本仓库内以 <skill_dir>\scripts\ 这份为准。