Files
MemRelay/projects/d5a7f581-c442-4554-87b9-ee723b8b0258/坑:Windows 目录改名被句柄锁死的破解法(句柄跟对象走).md
T

21 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: 坑:Windows 目录改名被句柄锁死的破解法(句柄跟对象走)
type: experience
permalink: main/projects/d5a7f581-c442-4554-87b9-ee723b8b0258/坑-windows-目录改名被句柄锁死的破解法句柄跟对象走
stable_id: bc21af00-1127-44f8-93b7-aa484a7041c2
scope: project
project_id: d5a7f581-c442-4554-87b9-ee723b8b0258
memory_type: experience
status: active
revision: 1
restored_from_commit: 6a6a895eafcca6052e81a14fca103a42635dd1c2
created_at: '2026-09-23T15:10:01.644507+00:00'
updated_at: '2026-09-23T15:10:01.644572+00:00'
tags:
- pitfall
- windows
- git
- submodule
---
现象:git mv 子模块目录报 Permission denied,Windows 下目录树内只要有任何打开的句柄,整树 rename 就会失败(与句柄共享模式无关)。本例是 Cursor IDE 持有子模块内嵌 .git 的目录句柄(.git、refs/remotes/origin)和 pack/idx 文件内存映射。排查:逐层 Rename-Item 二分定位被锁子项;用 Sysinternals handle64.exe(live.sysinternals.com 临时下载,用完删)查持锁进程。破解(无需重启 IDE/杀进程):Windows 句柄跟随对象而非路径,且单个被打开对象若共享 DELETE 可直接 Move-Item——把被锁对象逐个移出目录树(移到 temp),树内无句柄后整树 rename 成功,再把对象移回新位置;全程可逆。另:手动迁移子模块(非 git mv)后需补:.gitmodules 改 path(先 git add .gitmodules 否则 git rm 报 stage 错误)→ git rm --cached 旧路径 → git add 新路径(含 .git 的目录自动成 gitlink,embedded 警告可忽略)→ git submodule sync;内嵌 .git 自包含无需改指针,absorbed 子模块用 git mv 会自动处理。