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

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


当前回答

这也可能来自其他使用git的应用程序或插件 例如源树。在我的情况下,似乎有一些进程卡住了源树关于git。删除索引。锁档对我没用。我想删除项目目录下。git文件夹中的sourcetreconfig,它工作了。

rm -rf .git/index.lock
rm -rf .git/sourcetreeconfig

其他回答

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

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

2)删除Podfile。锁文件。

3)进行新的pod更新

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

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

例如,

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目录或在你的一个工作树。git/worktrees/*/index。如果您在工作树中,请锁定。

rm -f .git/index.lock

这类问题通常发生在同时执行两个git命令时;可能一个来自命令提示符,一个来自IDE。

除了删除。Git文件夹中的锁文件外,如果你正在使用Visual Studio Code和Git Graph扩展,请尝试卸载它,然后重新安装。它应该能解决这个问题。

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

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

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

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