当我试图移动我的项目树到git repo时,我仍然得到这个错误消息。

我检查了我的目录与这个项目的权限,这些设置为777。在终端的my_project目录下设置:

git init

然后如果我尝试

转到添加 。

or

Git commit -m "first upload"

我就会得到错误

fatal: Unable to create '/path/my_proj/.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.

我也尝试创建一个新的回购,并在那里提交它,但不幸的是,仍然是相同的错误消息。

问题的原因是什么?


当前回答

所有的解决方案都是正确的:

Just remove .git from your corrupted repository, 

then copy this file if back from another clone (if you don't have it in another machine, just clone it).

最后,是什么改变了我:

避免使用sudo解压或复制新的。git文件夹。如果您使用超级用户权限创建。Git将无法访问。Git文件夹

其他回答

如果你正在使用#intelliJ ide中的一个并接收到这个msg(我正在使用#webtorm),请注意这个问题可能会发生,因为隐藏了一个项目文件夹(在设置内部),这可以阻止git合并。

在Windows中,我只能在任务管理器中为所有Git Windows(32位)进程结束任务后删除锁文件。

解决方案(win10)

1. 结束任务管理器中所有Git Windows(32位)进程的任务

2. 删除.git/index。锁文件

对我来说

rm -r .git-credentials.lock 

需要删除索引。锁文件。

在Linux中

cd .git
rm -f index.lock

在Windows(10)中,在repo目录下的命令提示符中执行此操作:

cd .git
del index.lock

尝试退出Xcode——因为它是一个git客户端,你必须退出Xcode以避免命令行上的git问题。