Git rename from index.lock to index failed

Using the GitHub Windows client I did a sync to pull remote changes to my local machine, but before finishing the sync, I ran out of disk space and the sync failed. Now I seem to have a bunch of local changes that are actually changes that were being pulled from origin. I tried to run git pull but got:

C:UsersTomSourceLog [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

So now I'm trying to discard the local changes but I'm getting:

C:UsersTomSourceLog [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

How can I clean this up? (I didn't have any local changes before starting the sync.)

Update

Can't seem to reset head..

C:UsersTomSourceLog [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'.

Looks like the following process had a lock on the .gitindex file:

ssh-agent.exe
C:UsersTomAppDataLocalGitHubPortableGit_8810fd5c2c79c73adcc73fd0825f3b32fdb816e7binssh-agent.exe

I killed the process and ran git reset HEAD and looks like I'm back to normal now.


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

del .gitindex
git reset --mixed head

To discard local changes, go

git reset HEAD

Then checkout your old commit, delete the new one, and pull again.

git checkout "hashOld"
git branch -d "hashNew"
git pull
链接地址: http://www.djcxy.com/p/18852.html

上一篇: 如何检出旧的提交并将其提交给新的提交

下一篇: 从index.lock重命名为索引失败