草庐IT

windows - 如果 git index.lock 存在,我可以安全地删除它,还是需要更多操作来验证完整性?

coder 2024-06-08 原文

在过去的几周里,我收到了几次关于 index.lock 存在的消息。

删除该文件作为解决方案在 git index.lock File exists when I try to commit, but cannot delete the file

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

这是在安装了 git 命令行工具、TortoiseGIT 和 SourceTree 的 Windows x64 系统(完全修补)上。

最佳答案

没有other answers提及 index.lock 的用途。
然而,它记录在 Git 发行版中,位于文件“Documentation/technical/api-lockfile.txt”下。

Is deleting that file enough?

按照该文档,似乎删除就足够了。

锁文件API

The lockfile API serves two purposes:

  • 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.

  • 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 工具之一:

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

考虑到该文件是在 O_EXCL 锁定方案下创建的,它很可能无法创建,因为它被另一个 PID 锁定。
作为mentioned here :

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 年第 3 季度)

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

参见 commit 9e90331 , commit 18a3de4 , commit ebebeae , commit 00539ce , ...(巨大的 list ),commit 2db69de (2015 年 8 月 10 日)Michael Haggerty (mhagger) .
(由 Junio C Hamano -- gitster -- merge 于 commit db86e61 ,2015 年 8 月 25 日)

临时文件 API 允许创建、删除和自动重命名临时文件。
程序结束时仍处于事件状态的临时文件会自动清除。
锁定文件建立在这个 API 之上。

关于windows - 如果 git index.lock 存在,我可以安全地删除它,还是需要更多操作来验证完整性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20824746/

有关windows - 如果 git index.lock 存在,我可以安全地删除它,还是需要更多操作来验证完整性?的更多相关文章

  1. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  2. ruby - 在 Ruby 程序执行时阻止 Windows 7 PC 进入休眠状态 - 2

    我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0

  3. ruby - 我需要将 Bundler 本身添加到 Gemfile 中吗? - 2

    当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/

  4. ruby-on-rails - 如何验证 update_all 是否实际在 Rails 中更新 - 2

    给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru

  5. ruby - 具有身份验证的私有(private) Ruby Gem 服务器 - 2

    我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..

  6. ruby - 使用 Vim Rails,您可以创建一个新的迁移文件并一次性打开它吗? - 2

    使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta

  7. ruby-on-rails - 如果为空或不验证数值,则使属性默认为 0 - 2

    我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val

  8. ruby - 我可以使用 Ruby 从 CSV 中删除列吗? - 2

    查看Ruby的CSV库的文档,我非常确定这是可能且简单的。我只需要使用Ruby删除CSV文件的前三列,但我没有成功运行它。 最佳答案 csv_table=CSV.read(file_path_in,:headers=>true)csv_table.delete("header_name")csv_table.to_csv#=>ThenewCSVinstringformat检查CSV::Table文档:http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV/Table.html

  9. ruby-on-rails - 如何验证非模型(甚至非对象)字段 - 2

    我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss

  10. ruby - rspec 需要 .rspec 文件中的 spec_helper - 2

    我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只

随机推荐