git index.lock文件存在,当我尝试提交,但不能删除该文件

当我做'git提交'时,我得到以下内容:

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

但是,当我做ls project_path/.git/index.lock它说这个文件不存在。 任何想法我应该做什么? 我也注意到project_path / .git是由root拥有的,不知道是否与我遇到的问题有关。

git版本是1.7.5.4

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

这可能是一个旧的答复,但我希望这是更有用的下一个谁需要这个解决scheme。

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

rm -f .git/index.lock

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

del .git\index.lock

希望有所帮助,我在这里find了这个解决scheme: 致命:无法创build'… git / index.lock'文件存在

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

解决scheme:假设您要使用源代码树作为源代码pipe理器,只需在Visual Studio中禁用源代码pipe理提供程序,如下所示:

  1. 转到:工具>选项>源代码pipe理
  2. select“当前源代码pipe理插件”为:无

对于Windows:

  • 从作为pipe理员打开的PowerShell控制台,尝试
 > rm -f ./.git/index.lock 
  • 如果这不起作用,你必须杀死所有的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 -f ./.git/index.lock 
  1. 检查一下git是否还在运行(ps -ef | grep git)
  2. 如果没有,请删除locking的文件
  3. 如果是的话,先杀掉git进程。

这是发生在你从中间取消从原点拉动。

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

 rm -f ./.git/index.lock 

cd到你的项目目录并运行这个命令。

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

删除locking, 并确保你正在执行与正确的用户git,以避免权限问题。

如果你在使用sudo命令的GNU / Linux中:

sudo rm project_path / .git / index.lock

刚刚有这个问题… Gitbox是错的。 所以也许你有一个运行的GUI导致了问题。

有时Git创build一个locking文件与您的回购相关联,而您正在进行任何更改或最有可能当您使用子模块。 错误消息将显示locking文件的path。 修复:只需手动转到terminal的path,并通过$ rm index.lock删除locking文件

它应该帮助。

除非你真的打算让root用户拥有你的repo,否则这听起来像是你不小心以root身份运行了一个Git命令(甚至可能是最初的clone / init)。 如果你打算这样做,那么你将不得不以root身份运行在repo中的所有Git命令。 如果你没有,运行sudo chown your-user[:your-group] -R .git来获得它的所有权,然后看看是否有效。

好的,我已经解决了这个问题。

  1. closures每个可能影响这个.git / index.lock文件的窗口
  2. 删除.git / index.lock文件。
  3. 打开你的命令行编辑器,并cd到你的git文件的位置。

(如果文件是创build的,只需从cd到该位置,那么问题是你的编辑器,closures你的编辑器,不要再用这个编辑器来完成这个任务,打开一个不同的编辑器 – windows power shell或者简单的cmd。你可以使用git命令来继续)

通过双击它来切换分支时,我在SourceTree中遇到了这个问题。 问题不是很普遍, Atlassian知道这个问题,但是他们决定不修复这个问题。

幸运的是,有一个解决scheme。 而不是双击您想要切换的分支,只需右键单击并select“签出[分支名称]”。 现在应该成功了。

我也有这个问题在Windows 10中。

当我尝试删除./.git/index.lock ,它告诉我cannot remove 'index.lock': Device or resource busy

我终于明白了原因:

电脑有两个使用git的过程:

  • git bash
  • cmder

所以我使用cmder.exe来git commit它会发生错误。

所以解决scheme是使用git bash或者终止git bash然后使用cmder.exe

我有这个完全相同的错误,但问题不是locking文件。 相反,问题是我把另一个git仓库的内容复制到了这个仓库中,包括.git不可见的文件夹。 所以,SourceTree对我想把文件放到哪个回购站(我认为回归SourceTree和embedded式.git目录中的内容存在一个不匹配)感到困惑。

我在Windows上与Cygwin的TortoiseGit有这个问题。 我无法删除./.git/index.lock即使有pipe理权限,我尝试了Cygwin和命令提示符,它说该文件正在被另一个进程使用。

我发现我有2个TortoiseProc.exe运行的实例。 我杀了其中一个,并closures了我所有的Windows资源pipe理器窗口,然后才能够删除该文件。 我不知道是否杀死一个TortoiseProc.exe的实例是解决scheme或closuresWindows资源pipe理器窗口。

我的解决scheme是删除.index文件,并允许Git重build另一个。

我没有一个inex.lock文件来删除,但是对我而言,是从文件夹属性对话框的属性窗口中删除了只读检查。

我创build了一个空的index.lock文件,使用windows命令将其删除

在我的sourceTree应用程序中,我无法提交或切换到任何其他提交/布拉奇。 那个时候显示错误

致命:无法创build等等等等等等..

我只是解决这个goto .git文件夹(在项目资源pipe理器目录)。 并删除索引—– [文件types:LOCK文件]。现在我得到所有的访问在sourceTree ..

请确保索引locking文件..假设你没有得到文件types,更改计算机中的fileview设置。 注意:.git文件夹通常是隐藏文件夹的types。

在同一本地存储库上工作的多个git客户端争夺该锁。 每个客户都应该等到对方放开locking成为一个好公民。 对于我们来说,SourceTree或MSVS似乎是在后台运行大量提交脚本时进行一些维护。

也许“git”本身应该支持“–Locked 5Locked”,以支持重试。 甚至手动运行时甚至默认这个。

这是一个名为“gitr”的git包装器,它重试直到index.lock消失,使用默认5次尝试,每次间隔3秒。 它永远不会删除index.lock,假设用户应该介入。 它是从更大的提交脚本中提取的。 它只用简单的参数进行最less的testing。

  • 将脚本复制到C:\ bin并将C:\ bin添加到$ PATH。
  • 从PS1> gitr –help
  • 从DOS%> powershell gitr –help

gitr.ps1

  #requires -version 2 <# .SYNOPSIS gitr .DESCRIPTION Run "git" as an external process with retry and capturing stdout stderr. .NOTES 2017/05/16 crokusek: Initial version #> #---------------------------------------------------------[Initializations]-------------------------------------------------------- #Set Error Action $ErrorActionPreference = "Stop"; #----------------------------------------------------------[Declarations]---------------------------------------------------------- $scriptDir = Split-Path $script:MyInvocation.MyCommand.Path #Set-Location $scriptDir ## Disabled logging # Log File # $logFile = "$($scriptDir)\getr.log" # If (Test-Path $logFile) { Clear-Content $logFile } #-----------------------------------------------------------[Functions]------------------------------------------------------------ Function Log([string]$msg, [bool]$echo = $true) { $timestamp = "$(get-date -Format 'yyyy/MM/dd HH:mm:ss'): " $fullmsg = $msg -replace '(?ms)^', $timestamp # the (?ms) enables multiline mode ## Disabled Logging # Add-content $LogFile -value $fullmsg if ($echo) { Write-Host $msg } } Function ExecSimple([string]$command, [bool]$echo=$true, [bool]$stopOnNonZeroExitCode=$true) { $command, $args = $command -split " " return Exec $command $args $echo $stopOnNonZeroExitCode } Function Exec([string]$exe, [string[]]$arguments, [bool]$echo=$true, [bool]$stopOnNonZeroExitCode=$true) { # Passing $args (list) as a single parameter is the most flexible, it supports spaces and double quotes $orgErrorActionPreference = $ErrorActionPreference Try { $error.clear() # this apparently catches all the stderr pipe lines if ($false -and $exe -eq 'git') # todo make this a generic flag { $exe = "$($exe) 2>&1" } $output = "" $argflattened = $arguments -join ' ' Log "`n% $($exe) $($arguments)`n" # This way some advantages over Invoke-Expressions or Start-Process for some cases: # - merges stdout/stderr line by line properly, # - echoes the output live as it is streamed to the current window, # - waits for completion # - works when calling both console and windows executables. # $ErrorActionPreference = "Continue" # required in order to catch more than 1 stderr line in the exception if ($echo) { # Using "cmd.exe" allows the stderr -> stdout redirection to work properly. Otherwise the 2>&1 runs after PS for # some reason. When a command such as "git" writes to stderr, powershell was terminating on the first stderr # line (and stops capturing additional lines). # # but unfortuantely cmd has some bizarre de-quoting rules that weren't working for all cases. #& cmd /c "`"" $exe $arguments "`"" | Tee-Object -variable output | Write-Host | out-null # This is simplest but has some issues with stderr/stdout (stderr caught as exception below) # & $exe $arguments 2>&1 | tee -variable output | Write-Host | out-null } else { & $exe $arguments 2>&1 | tee -variable output | out-null } $output = $output -join "`r`n" if ($stopOnNonZeroExitCode -and !$LASTEXITCODE -eq 0) { throw [System.Exception] "Exit code ($($LASTEXITCODE)) was non-zero. Output:`n$($output)" } } catch [System.Management.Automation.RemoteException] { $output = $_.Exception.ToString().Replace("System.Management.Automation.RemoteException:", "").Trim() if ($output.Contains("fatal")) { throw } if ($echo) { Log $output } } finally { $ErrorActionPreference = $orgErrorActionPreference; } if (-not $output -eq "") { Log $output $false # don't echo to screen as the pipe above did } return $output } Function ExecWithRetry([string]$exe, [string[]]$arguments, [bool]$echo=$true, [bool]$stopOnNonZeroExitCode=$true, [int]$maxRetries = 5, [int]$msDelay = 3000, [AllowNull()][string]$exceptionMustContain = $null) { for ($i = 0; $i -lt $maxRetries; $i++) { try { Exec $exe $arguments $echo $stopOnNonZeroExitCode return } catch { if (-not [string]::IsNullOrEmpty($exceptionMustContain) -and $_.Exception.ToString().Contains($exceptionMustContain)) { Log "Last Error from $($exe) is retryable ($($i + 1) of $($maxRetries))" $true Start-Sleep -Milliseconds ($msDelay); continue } throw } } throw [System.Exception] "Unable to successfully exec '$($exe)' within $($maxRetries) attempts." } Function GitWithRetry([string[]]$arguments, [bool]$echo=$true) { ExecWithRetry "git" $arguments $echo -exceptionMustContain "Another git process seems to be running" } #-----------------------------------------------------------[Main]------------------------------------------------------------ function Main([string[]]$arguments) { GitWithRetry @($arguments) } #-------------------------------------- Startup ------------------------------------ try { Main $args Exit 0 } catch { #Log "*** A fatal error occured: $($_.Exception)" #Read-Host -Prompt "`nA fatal error occurred, press enter to close." exit 1 } 

获取错误:

 Using index info to reconstruct a base tree... Falling back to patching base and 3-way merge... fatal: Unable to create '/home/user/project/.git/index.lock': File exists. If no other git process is currently running, this probably means a git process crashed in this repository earlier. Make sure no other git process is running and remove the file manually to continue. 

但是我找不到(或删除).git / index.lock文件。

就我而言,git-cola正在运行!

它显然创造了.git / index.lock每隔一段时间,或由于我在命令行上做了rebase,并在此期间我收到错误 – 所以git-cola显然“干扰”Git的命令行运行(或者一些Git CLI操作)。

这是通过在命令行git rebase期间closuresgit-cola来解决的。

有时候,有多个Git客户端可能会干扰多个安装。

IE浏览器。 请确保任务pipe理器或Get-Process从TortoiseGit的TGitCache在后台不活动。

开始git 2.8.4(2016年6月) ,这不应该发生了。

参见问题755也应该减轻问题( 提交2db0641 ):

确保临时文件句柄不被subprocessinheritance

防止subprocessinheritance到index.lock的句柄。

我最近有同样的问题。 如果你将检查整个错误消息,它也说有一些进程正在使用git进程阻止你删除index.lock。 您可能会将IDE打开为像Visual Studio或git所集成的相关软件。 closures它,并尝试重新存储您的文件。 希望能帮助到你。

如果您使用GIT BASH For Windows: –

运行这两个命令1. cd .git 2. rm index.lock