我试图学习如何使用Git,并创建了一个带有HTML, CSS和JavaScript文件的小项目。我从我的基本空项目做了一个分支,然后对我的代码做了一些更改。我尝试进行临时更改,但我得到以下错误消息:

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 Bash,因为我不知道如何摆脱我以某种方式得到的。

是否有办法解决这个问题,或者我应该开始一个新的存储库?


当前回答

错误代码将为您提供文件的完整路径。复制该路径并删除该文件。

例如,

fatal: Unable to create '/Users/username/Development/project/.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.
rm -rf fullPathOftheFile
rm -rf /Users/username/Development/project/.git/index.lock

其他回答

这种情况发生在我身上,虽然sourcetree一直告诉我锁文件存在,但没有这样的文件供我删除。所以我只是签出了另一个分支,然后返回到原来的分支,并注意到这个更改修复了问题。

我也面临着类似的问题。我是一个Windows用户,所以前面所有的答案都是使用命令行Git Bash或任何其他。我手动使用了以下方法,它对我很有效:

步骤1:

转到您要推的项目目录。

在我的例子中,它是E——移动

步骤2:

在文件夹视图设置中启用显示隐藏文件夹

步骤3:

启用show hidden folder后,您将在项目目录中获得.git文件。 打开。git文件夹并找到索引。锁定文件,并删除它。

现在您可以轻松地输入代码。

如果您正在使用CocoaPods,并且在某个时候搞砸了更新或安装(手动杀死它或其他),请尝试一下

1)删除索引。锁定文件(在.git/index.lock中)

2)删除Podfile。锁文件。

3)进行新的pod更新

4)尝试发出失败的git命令(在我的情况下,它是一个git添加。)

删除我的提交信息对我有用。

rm .git/COMMIT_EDITMSG

它接着说。

fatal:无法锁定ref 'HEAD':无法创建'.git/refs/heads/[your-branch-name]。lock `:文件已存在。

请注意,您的分支名称可能与我的不同。您可以通过执行;

rm .git/refs/heads/[your-branch-name].lock

错误代码将为您提供文件的完整路径。复制该路径并删除该文件。

例如,

fatal: Unable to create '/Users/username/Development/project/.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.
rm -rf fullPathOftheFile
rm -rf /Users/username/Development/project/.git/index.lock