当我尝试提交时,git index.lock 文件存在,但无法删除该文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9282632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:59:04  来源:igfitidea点击:

git index.lock File exists when I try to commit, but cannot delete the file

git

提问by asahi

When I do 'git commit', I'm getting the following:

当我执行 'git commit' 时,我得到以下信息:

fatal: Unable to create 'project_path/.git/index.lock': File exists.

fatal: Unable to create 'project_path/.git/index.lock': File exists.

However, when I do ls project_path/.git/index.lockit's saying the file doesn't exist. Any thoughts on what I should do? I've also noticed that project_path/.git is owned by root, not sure if that has anything to do with the problem I'm encountering.

但是,当我这样做时,ls project_path/.git/index.lock它说该文件不存在。关于我应该做什么的任何想法?我还注意到 project_path/.git 归 root 所有,不确定这是否与我遇到的问题有关。

git version is 1.7.5.4

git 版本是 1.7.5.4

edit: It seems that the problem most likely was another process I had running, that was writing (unbeknownst to me) to the project directory. I restarted my machine and then I had no problem committing.

编辑:似乎问题很可能是我运行的另一个进程,即写入(我不知道)到项目目录。我重新启动了我的机器,然后我没有问题提交。

回答by Ryan S

This may be an old reply but I'm hoping this is more useful on next who need this solution.

这可能是一个旧回复,但我希望这对下一个需要此解决方案的人更有用。

On linux/unix/gitbash/cygwin, try

在 linux/unix/gitbash/cygwin 上,尝试

rm -f .git/index.lock

rm -f .git/index.lock

On Windows Command Prompt, try:

在 Windows 命令提示符下,尝试:

del .git\index.lock

del .git\index.lock

回答by Andrei Epure

For Windows:

对于 Windows:

  • From a powershell console opened as admin, try
  • 从以管理员身份打开的 powershell 控制台,尝试
> rm -Force ./.git/index.lock
> rm -Force ./.git/index.lock
  • If that does not work, you must kill all git.exe processes
  • 如果这不起作用,您必须杀死所有 git.exe 进程
> taskkill /F /IM git.exe
SUCCESS: The process "git.exe" with PID 20448 has been terminated.
SUCCESS: The process "git.exe" with PID 11312 has been terminated.
SUCCESS: The process "git.exe" with PID 23868 has been terminated.
SUCCESS: The process "git.exe" with PID 27496 has been terminated.
SUCCESS: The process "git.exe" with PID 33480 has been terminated.
SUCCESS: The process "git.exe" with PID 28036 has been terminated.
> rm -Force ./.git/index.lock
> taskkill /F /IM git.exe
SUCCESS: The process "git.exe" with PID 20448 has been terminated.
SUCCESS: The process "git.exe" with PID 11312 has been terminated.
SUCCESS: The process "git.exe" with PID 23868 has been terminated.
SUCCESS: The process "git.exe" with PID 27496 has been terminated.
SUCCESS: The process "git.exe" with PID 33480 has been terminated.
SUCCESS: The process "git.exe" with PID 28036 has been terminated.
> rm -Force ./.git/index.lock

回答by WLCyPHlSpC

On a Windows platform running Visual Studio 2015 RC (v4.6.00057) in combination with SourceTree (v1.6.14.0) will give this error as well.

在运行 Visual Studio 2015 RC (v4.6.00057) 和 SourceTree (v1.6.14.0) 的 Windows 平台上也会出现此错误。

Solution: Assuming you want to use source tree as source code manager, simply disable the source control provider inside Visual Studio like this:

解决方案:假设您想使用源代码树作为源代码管理器,只需像这样禁用 Visual Studio 中的源代码控制提供程序:

  1. Go to: Tools > Options > Source Control
  2. Select Current source control plug-in as: None
  1. 转到:工具 > 选项 > 源代码管理
  2. 选择当前源控制插件为:无

回答by Daniel YC Lin

  1. check if the git still running (ps -ef | grep git)
  2. if not, remove the locked file
  3. if yes, kill the git process at first.
  1. 检查 git 是否仍在运行 (ps -ef | grep git)
  2. 如果没有,请删除锁定的文件
  3. 如果是,首先杀死 git 进程。

回答by Touseef Murtaza

try

尝试

rm -f ./.git/index.lock

if you have no other git process running, then just delete the index.lock file of the respective project.

如果您没有其他 git 进程在运行,则只需删除相应项目的 index.lock 文件即可。

回答by Rahul Vivek

This is happening when you are do cancel pulling from origin in the middle.

当您在中间取消从原点拉动时会发生这种情况。

so what you can do is manually delete index.lock file from your .git directory.

所以你可以做的是从你的 .git 目录中手动删除 index.lock 文件。

rm -f ./.git/index.lock

cd into you project directory and run this command.

cd 进入您的项目目录并运行此命令。

回答by MyztikJenz

Just had this issue... Gitbox was at fault. So maybe you had a GUI running that was causing problems.

刚刚遇到这个问题……Gitbox 有问题。因此,也许您运行的 GUI 导致了问题。

回答by caligari

Probably (it has happened to me), lscommand is saying it doesn't existbecause current user doesn't have permissions to reach that directory or file.

可能(它发生在我身上),ls命令说它不存在,因为当前用户没有访问该目录或文件的权限。

Remove the lock and make sure you are executing git with the right userin order to avoid permission problems.

移除锁定并确保您使用正确的用户执行 git以避免权限问题。

If you are in a GNU/Linux box with sudocommand:

如果您在使用sudo命令的 GNU/Linux 机器中:

sudo rm project_path/.git/index.lock

须藤rm project_path/.git/index.lock

回答by Steve Tomlin

  1. Close every window that is potentially affecting this .git/index.lock file
  2. Delete the .git/index.lock file.
  3. Open your command line editor and cd to the location of your git files.
  1. 关闭可能影响此 .git/index.lock 文件的每个窗口
  2. 删除 .git/index.lock 文件。
  3. 打开命令行编辑器并 cd 到 git 文件所在的位置。

( If the file is created, simply from cd into that location, then the problem is your editor. Close your editor. Do not use this editor again for this task. Open a different kind of editor - windows power shell or simply cmd. Now you can use git commands to continue)

(如果文件已创建,只需从 cd 到该位置,那么问题出在您的编辑器。关闭您的编辑器。不要再次使用此编辑器执行此任务。打开不同类型的编辑器 - windows power shell 或简单的 cmd。现在您可以使用 git 命令继续)

回答by Nikhil Shrivastav

del .git\index.lockworked for me.

del .git\index.lock对我来说有效。

I was facing this issue while checkout a new branch from master branch.

我在从 master 分支结帐新分支时遇到了这个问题。

Checkout easily happened after deleting the index.lockfile.

删除index.lock文件后很容易发生结帐。