Git - 文件 .idx 和 .pack 的取消链接失败(该文件的唯一进程拥有句柄是 git.exe)

Git - Unlink of file .idx and .pack failed (The only process owned handle to this file is git.exe)

请看这张照片! git 有那么蠢吗? Git 无法取消链接某些文件,但只有 git.exe 持有此文件的句柄。 (权限没问题 - 完全控制) 请问,这个问题有安全的解决方案吗? 我的 Git 版本是 1.9.5-preview20141217

我遇到了这个问题并通过以下命令解决了它:git gc 上面的命令删除了临时文件和不需要的文件(垃圾收集器):

Git 2.19(2018 年第 3 季度)改进了包文件的文件描述符管理,并避免了“Unlink of file... failed. Should I try again?”错误消息。

参见 commit 12e73a3 (09 Jul 2018) by Kim Gybels (dscho)
(由 Junio C Hamano -- gitster -- in commit 562413e 合并,2018 年 8 月 2 日)

gc --auto: release pack files before auto packing

"git gc --auto" opens file descriptors for the packfiles before spawning "git repack/prune", which would upset Windows that does not want a process to work on a file that is open by another process.

Teach gc --auto to release pack files before auto packing the repository to prevent failures when removing them.

Also teach the test 'fetching with auto-gc does not lock up' to complain when it is no longer triggering an auto packing of the repository.

这解决了 Git for Windows issue "Unlink of file XXX failed. Should I try again?", with PR 1769.


另一项改进:在 Git 2.34(2021 年第 4 季度)中,运行-命令 API 已更新,以便调用者可以轻松请求打开包文件的文件描述符在可能触发 auto-gc.

的生成命令之前立即关闭

参见 commit c4dee2c, commit 5a22a33, commit 28d04e1, commit 3322a9d (09 Sep 2021), and commit 7e44ff7, commit 957ba81 (08 Sep 2021) by Johannes Schindelin (dscho)
(由 Junio C Hamano -- gitster -- in commit c042ad5 合并,2021 年 9 月 20 日)

c4dee2c085:Close object store closer to spawning child processes

Signed-off-by: Johannes Schindelin

In many cases where we spawned child processes that may trigger a repack, we explicitly closed the object store first (so that the repack process can delete the .pack files, which would otherwise not be possible on Windows since files cannot be deleted as long as they as still in use).

Wherever possible, we now use the new close_object_store bit of the run_command() API, to delay closing the object store even further.
This makes the code easier to maintain because it is now more obvious that we only release those file handles because of those child processes.