如果git index.lock存在,我可以安全地将其删除,还是需要执行更多操作来验证完整性? [英] if git index.lock exist, can I safely delete it, or are more actions needed to verify integrity?

查看:163
本文介绍了如果git index.lock存在,我可以安全地将其删除,还是需要执行更多操作来验证完整性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几周中,我收到了有关index.lock的消息,该消息存在了几次.

Over the last couple of weeks I got a message about index.lock to exist a few times.

在解决方案中提到删除该文件 git索引.lock文件在我尝试提交时存在,但无法删除该文件

Deleting that file is mentioned as solution in git index.lock File exists when I try to commit, but cannot delete the file

删除该文件是否已足够,或者我还需要执行其他操作(是否有验证完整性的方法?).

Is deleting that file enough, or are there other actions I should need to do (are there ways to verify integrity and such?).

这是在装有git命令行工具,已安装TortoiseGIT和SourceTree的Windows x64系统(已全面修补)上.

This is on a Windows x64 system (fully patched) with git commandline tools, TortoiseGIT and SourceTree installed.

推荐答案

其他

None of the other answers mention what that index.lock is for.
Yet, it is documented in a Git distribution, under the file "Documentation/technical/api-lockfile.txt".

删除该文件是否足够?

Is deleting that file enough?

在该文档之后,看来删除就足够了.

Following that documentation, it appears that deleting is enough.

lockfile API有两个用途:

The lockfile API serves two purposes:

  • 互斥.
    当我们写出新的索引文件时,首先我们创建一个新文件$GIT_DIR/index.lock,将新内容写入其中,然后将其重命名为最终目标$GIT_DIR/index.我们尝试使用O_EXCL创建$GIT_DIR/index.lock文件,以便在其他人已经在尝试更新索引文件时注意到并失败.

  • Mutual exclusion.
    When we write out a new index file, first we create a new file $GIT_DIR/index.lock, write the new contents into it, and rename it to the final destination $GIT_DIR/index. We try to create the $GIT_DIR/index.lock file with O_EXCL so that we can notice and fail when somebody else is already trying to update the index file.

自动清除残渣.
创建锁定"文件后,我们可能决定使用die(),并且我们要确保我们删除尚未提交到最终目的地的文件.
这可以通过记住我们在链表中创建的锁文件并从atexit(3)处理程序中清除它们来完成.当程序死于信号时,也会删除未完成的锁定文件.

Automatic cruft removal.
After we create the "lock" file, we may decide to die(), and we would want to make sure that we remove the file that has not been committed to its final destination.
This is done by remembering the lockfiles we created in a linked list and cleaning them up from an atexit(3) handler. Outstanding lockfiles are also removed when the program dies on a signal.

在Windows上,应该不会出现权限问题(例如一个Git工具将该文件创建为"root").
唯一的问题是您的Windows工具之一:

On Windows, there shouldn't be a permission issue (like one Git tool creating that file as 'root').
The only issue would be for one of your Windows tools to:

  • 以系统帐户而不是用户帐户运行
  • 或开始暂存文件(意味着创建索引和创建index.lock文件),并具有另一个工具来开始暂存同一存储库中的文件.

考虑到该文件是根据O_EXCL锁定方案创建的,因此很可能无法创建该文件,因为该文件已被另一个PID锁定.
正如
此处提到的:

Considering that file is creating under the O_EXCL locking scheme, it is likely it cannot be created because it is locked by another PID.
As mentioned here:

O_EXCL唯一要做的是,如果文件存在并且指定了O_CREAT,则会导致调用失败.

The only thing O_EXCL does is cause the call to fail if the file exists and O_CREAT is specified.


2015年8月更新,适用于git 2.6+(2015年第三季度)


Update August 2015, for git 2.6+ (Q3 2015)

已在新的"tempfile" API之上重建了"lockfile" API. /a>

The "lockfile" API has been rebuilt on top of a new "tempfile" API.

请参见提交9e90331 提交ebebeae 提交00539ce ,...(大列表),提交2db69de (2015年8月10日)通过 Junio C Hamano-gitster-

See commit 9e90331, commit 18a3de4, commit ebebeae, commit 00539ce, ...(huge list), commit 2db69de (10 Aug 2015) by Michael Haggerty (mhagger).
(Merged by Junio C Hamano -- gitster -- in commit db86e61, 25 Aug 2015)

tempfile API允许创建,删除和原子重命名临时文件.
程序结束时仍处于活动状态的临时文件将自动清除.
锁定文件是建立在此API之上的.

The tempfile API allows temporary files to be created, deleted, and atomically renamed.
Temporary files that are still active when the program ends are cleaned up automatically.
Lockfiles are built on top of this API.

这篇关于如果git index.lock存在,我可以安全地将其删除,还是需要执行更多操作来验证完整性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆