Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试提交时,git index.lock文件存在,但无法删除该文件_Git - Fatal编程技术网

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

尝试提交时,git index.lock文件存在,但无法删除该文件,git,Git,当我执行“git commit”时,我得到以下信息: 致命:无法创建“project\u path/.git/index.lock”:文件存在。 但是,当我执行ls project\u path/.git/index.lock时,它表示该文件不存在。我该怎么做有什么想法吗?我还注意到project_path/.git归root所有,不确定这是否与我遇到的问题有关 git版本是1.7.5.4 编辑:看来问题最有可能是我运行的另一个进程,即(我不知道)写入项目目录。我重新启动了我的机器,然后提交时没

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

致命:无法创建“project\u path/.git/index.lock”:文件存在。

但是,当我执行
ls project\u path/.git/index.lock
时,它表示该文件不存在。我该怎么做有什么想法吗?我还注意到project_path/.git归root所有,不确定这是否与我遇到的问题有关

git版本是1.7.5.4


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

除非您实际上打算让root拥有您的repo,否则这听起来像是您意外地以root身份运行Git命令(甚至可能是最初的clone/init)。如果您想这样做,那么您必须以root用户身份运行repo中的所有Git命令。如果没有,请运行
sudo chown您的用户[:您的组]-R.git
以获得它的所有权,然后查看是否工作。

刚刚出现此问题。。。吉特博克斯错了。因此,可能您运行的GUI导致了问题。

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

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

rm-f.git/index.lock

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


del.git\index.lock

  • 检查git是否仍在运行(ps-ef | grep git)
  • 如果没有,请删除锁定的文件
  • 如果是,请首先终止git进程
  • 可能(我也遇到过这种情况),ls命令说它不存在,因为当前用户没有访问该目录或文件的权限

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

    如果您在带有sudo命令的GNU/Linux机箱中:

    sudo rm project_path/.git/index.lock


    有时候,Git会在您进行任何更改时或在您使用子模块时创建一个与您的回购相关联的锁文件。 错误消息将显示锁定文件的路径。 修复:只需手动转到终端中的路径并通过 $rm index.lock


    这应该会有帮助。

    我也有同样的错误,但问题不是锁文件。相反,问题是我将另一个git repo的内容复制到了这个repo中,包括.git不可见文件夹。因此,SourceTree对我要将文件转移到哪个repo感到困惑(repo SourceTree认为我在其中,而embedded.git dir的内容说我应该在其中,两者之间存在不匹配)。

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


    我发现我有两个正在运行的TortoiseProc.exe实例。我杀死了其中一个,关闭了所有的windows资源管理器窗口,然后可以删除该文件。我不知道杀死一个TortoiseProc.exe实例是解决方案还是关闭windows资源管理器窗口。

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

    解决方案: 假设要将源代码树用作源代码管理器,只需在Visual Studio中禁用源代码管理提供程序,如下所示:

  • 转到:工具>选项>源代码管理
  • 选择当前源代码管理插件为:无

  • 我的解决方案是删除.index文件并允许Git重建另一个文件。

    获取错误:

    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期间关闭git-cola来解决。

    我没有要删除的inex.lock文件,但对我有效的是从文件夹属性对话框的属性窗口中删除只读检查。

    我创建了一个空的index.lock文件,使用Windows命令

    删除它。这是发生在你从中间开始取消拉的时候。

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

    rm -f ./.git/index.lock
    
    将cd放入项目目录中并运行此命令。

    开始时,不应再发生这种情况

    请查看哪个选项也可以缓解问题():

    确保子进程未继承临时文件句柄 防止子进程将句柄继承到
    index.lock


    在我的sourceTree应用程序中,我无法执行提交或切换到任何其他提交/分支。这段时间显示出错误的样子

    致命:无法创建废话废话

    我只是通过goto.git文件夹(在projectexplorerdir中)来解决这个问题。并删除索引------[文件类型:锁定文件]。现在我恢复了sourceTree中的所有访问权限


    请确保索引锁定文件。。假设您没有获取文件类型,请更改计算机中的文件视图设置。注意:.git文件夹通常是隐藏类型的文件夹。

    我在双击SourceTree切换分支时遇到了这个问题。这个问题并不常见,但他们决定不解决它

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

    对于Windows:

    • 从以管理员身份打开的powershell控制台中,尝试
    • 如果这不起作用,则必须杀死所有git.exe进程
  • > 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
    
        #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
    }
    
    rm -f ./.git/index.lock
    
    shutdown /s