我试图学习如何使用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

其他回答

它类似于上述方法,但在我的情况下,我有几个这样的方法

.git/refs/heads/<branch_name>.lock

通过这种方法,可以一次性去除

find -name "*.lock" -exec xargs rm {} \;

Rm -f .git/index。锁不起作用,因为我有一个无法删除的锁定文件。因此,索引。锁也被一些应用程序捕获了。

在Windows系统中,我下载了一个名为Lock Hunter的Unlocker替代品,并删除了这两个文件。Git抓住了他们。

对我来说,问题更简单。这是在Sourcetree中,所以我不确定它在多大程度上适用于常规解决方案,但我无意中选择了我的主分支,试图提交而不是未提交的更改。

这通常不是问题,但我已经预先输入了一个提交消息,所以我可以跟踪我在这个小冲刺中所做的事情。

基本上,我在未提交的分支上开始了一次提交,并意外地试图在我的主分支上开始另一次提交。

在我的例子中,只需运行命令:yarn add commitizen -D

那么一切都好了!

执行此命令时,

del /f index.lock

你会得到如下的回答,

该进程无法访问该文件,因为它正被另一个进程使用。

您可以使用process hacker等程序重新启动Windows中的git.exe进程。当Git重新启动时,锁就消失了。