Git从index.lock重命名为索引失败

Tom*_*ter 35 windows git github windows-7

使用GitHub Windows客户端我进行了同步以将远程更改提取到本地计算机,但在完成同步之前,我的磁盘空间不足,同步失败.现在我似乎有一堆本地更改,实际上是从原点中提取的更改.我试着运行git pull但得到了:

C:\Users\Tom\SourceLog [master +4 ~26 -0 !]> git pull
Updating b3a86e1..5afd74f
error: Your local changes to the following files would be overwritten by merge:
        SourceLog.Interface/IChangedFile.cs
        SourceLog.Interface/ILogEntry.cs
        ...
Please, commit your changes or stash them before you can merge.
error: The following untracked working tree files would be overwritten by merge:
        Lib/MSBuildExtensionPack/4.0.6.0/Ionic.Zip.dll
        Lib/MSBuildExtensionPack/4.0.6.0/MSBuild.ExtensionPack.dll
        ...
Aborting
Run Code Online (Sandbox Code Playgroud)

所以现在我想丢弃当地的变化,但我得到了:

C:\Users\Tom\SourceLog [master +4 ~26 -0 !]> git checkout -- .
Rename from '.git/index.lock' to '.git/index' failed. Should I try again? (y/n) y
Rename from '.git/index.lock' to '.git/index' failed. Should I try again? (y/n) n
fatal: unable to write new index file
Run Code Online (Sandbox Code Playgroud)

我该如何清理它?(在开始同步之前,我没有任何本地更改.)

更新

似乎无法重置头..

C:\Users\Tom\SourceLog [master +4 ~0 -0 !]> git reset head
Rename from '.git/index.lock' to '.git/index' failed. Should I try again? (y/n) y
Rename from '.git/index.lock' to '.git/index' failed. Should I try again? (y/n) n
error: Could not write new index file.
fatal: Could not reset index file to revision 'head'.
Run Code Online (Sandbox Code Playgroud)

Tom*_*ter 27

看起来以下进程锁定了.git\index文件:

ssh-agent.exe
C:\Users\Tom\AppData\Local\GitHub\PortableGit_8810fd5c2c79c73adcc73fd0825f3b32fdb816e7\bin\ssh-agent.exe
Run Code Online (Sandbox Code Playgroud)

我杀了这个过程跑了git reset HEAD,看起来我现在已恢复正常了.

  • 我想甚至不需要做`git reset HEAD`.没有它,它对我有用! (6认同)
  • 我遇到了同样的问题,对我来说有锁的进程是 Visual Studio Code(或与之相关的东西),因为当我关闭它时,它按预期工作。 (5认同)

tha*_*s.a 26

就我而言,我必须关闭WSL Ubuntu 终端打开的VS代码。code .

  • 这正是发生在我身上的事。但我必须关闭 vscode 才能进行 git 提交,这仍然是一个痛苦。 (2认同)

Dim*_*gog 15

在我的情况下,这是由管理员和非管理员命令提示使用相同的Git repo引起的.当last git pull来自admin cmd时,它index是由它创建的,然后非admin cmd没有足够的权限来修改它.

我的解决方案是重新创建index(同时保持工作树完好无损):

del .git\index
git reset --mixed head
Run Code Online (Sandbox Code Playgroud)

  • @ A.Blesius是的,`--mixed`是默认设置,但是我明确了它,因为`reset`命令看起来很吓人。 (3认同)
  • 通过删除.git / index和.git / index.lock为我工作 (2认同)
  • 嗨,通常不需要指定`--mixed`,因为它已经是标准了:https://git-scm.com/docs/git-reset#git-reset---mixed (2认同)

Ham*_*iou 7

这可能是一个真正的问题,尝试以管理员身份而不是用户身份运行您的终端。为我工作

  • 这是我的问题。`.git` 所在的位置位于受保护的文件夹中 (2认同)

Jas*_*ans 6

Rename from '.git/index.lock'...在尝试执行时看到了这条消息

git checkout -b my-branch

我的解决方法是将命令行作为admin.

具体来说,我以非管理员身份使用优秀的cmder应用程序,这导致出现重命名消息。通过以管理员身份运行cmder,然后再次执行结帐,它运行良好。