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

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


当前回答

首先,运行

rm -f .git/index.lock

然后运行

git reset --hard

在命令提示符或Git Bash中。

其他回答

我刚开始学习Python,就遇到了这个问题。在通读并尝试了针对这个问题提供的所有可能的解决方案后,没有一个对我有效。我使用的是Windows 10 64位系统。Visual Studio代码文本编辑器。

所以我简单地复制并粘贴venv文件夹到.git文件夹中,就这样了。

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

如果你不幸使用了你的git或git remove从git总线,或者你不能提交你的代码和“git add .”并远程上传代码,那么请检查以下内容。

这个命令… 假设您的错误类型

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总线或Windows PowerShell 然后使用下面的命令 rm . / index.lock

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

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

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

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

例如,

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