今天在使用 Git ,当我 pull 时,失败了,日志为:
Couldn't save uncommitted changes.
Tried to save uncommitted changes in stash before Update, but failed with an error.
Couldn't stash file://**: Unable to create '../.git/index.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
它显示当前仓库已经有一个 git 进程在运行了,让我们关掉所有进程后重试,但是我的项目刚刚才打开,也没有运行 git 命令,而且打开了任务管理器,也没有发现多的 git 进程。
我看到 git 命令失败的原因是因为 .git 目录下的 index.lock 文件已经存在了,那么这个 index.lock 文件是干啥的呢?是为了防止你对同一个仓库在同时进行多个操作,在一些耗时的 git 操作时自动生成的。那为什么第一次打开项目,没有进行过 git 操作也有这个文件呢?其实是有可能你上一次进行 git 操作时,git 操作还没有完成,你就强行关闭了,导致这个文件没有被自动删除。
那我们就手动删除就可以了,我们打开这个项目的根目录,打开 /.git 目录,删除 index.lock 文件就可以。