当我做'git commit'时,我得到以下内容:

无法创建“project_path/.git/index”。lock `:文件已存在。

然而,当我执行ls project_path/.git/index。锁定,表示文件不存在。你觉得我该怎么做?我还注意到project_path/。git由root拥有,不确定这是否与我遇到的问题有关。

Git版本为1.7.5.4

编辑:看起来问题很可能是我正在运行的另一个进程,那就是向项目目录写入(我不知道)。我重新启动了我的电脑,然后我就没有问题了。


当前回答

你的代码是否在Dropbox正在同步的目录中?试着暂停Dropbox。

我一直得到同样的情况,但一旦我暂停Dropbox(界面给你选择暂停30分钟,1小时,…),它再也没有发生过。

其他回答

try

rm -f ./.git/index.lock

如果没有其他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。锁文件。

在我的情况下,吉特可乐正在运行!

它显然创建了。git/index。每隔一段时间就会锁一次,或者是由于我在命令行上所做的更改而导致的,在此期间我收到了这个错误-所以Git -cola显然会“干扰”Git的命令行运行(或一些Git CLI操作)。

这可以通过在命令行git rebase期间关闭git-cola来解决。

在任务管理器中:

开发所有流程 关闭所有git进程 删除锁定文件

除非你真的打算让根用户拥有你的repo,否则这听起来像是你意外地以根用户身份运行了Git命令(甚至可能是初始的clone/init)。如果您打算这样做,那么您将不得不以根用户身份在repo中运行所有Git命令。如果没有,运行sudo chown your-user[:your-group] -R .git来获得它的所有权,然后看看事情是否正常。

对我来说,罪魁祸首是windows安全,它阻止了git.exe运行,你可以检查屏幕右下角的通知选项卡。

消息将如下所示

Virus and threat protection 
unauthorized changes blocked
controlled folder access blocked git.exe from running