另一个git进程似乎在这个存储库中运行

Mat*_*rby 544 git

我正在尝试学习如何使用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.
Run Code Online (Sandbox Code Playgroud)

当然,我确实遇到了一些问题,试图提前提交我的空项目,然后退出git bash因为我不知道如何摆脱我以某种方式得到的地方.

有什么方法可以解决这个问题,还是我应该开始一个新的存储库?

小智 1028

尝试删除index.lock目录中的.git文件.

rm -f .git/index.lock

当您git同时执行两个命令时,通常会出现此类问题; 也许一个来自命令提示符,一个来自IDE.

  • 如果那里没有`index.lock`文件,检查`HEAD.lock`·删除它为我解决了问题。 (8认同)
  • 我收到以下错误:rm:无法删除'.git/index.lock':设备或资源繁忙 (7认同)
  • 使用`rm -f .git/index.lock`删除 (6认同)
  • @DanielShatz 在 Windows 10 上删除“HEAD.lock”(使用 Sourcetree)就成功了。谢谢! (3认同)

M.J*_*M.J 54

在应用程序的根目录中使用以下命令.这将删除index.lock文件并释放活动锁.

rm .git/index.lock
Run Code Online (Sandbox Code Playgroud)


Ibn*_*shd 27

删除我的提交消息对我有用.

rm .git/COMMIT_EDITMSG
Run Code Online (Sandbox Code Playgroud)

然后说.

致命:无法锁定参考'HEAD':无法创建'.git/refs/heads/[your-branch-name] .lock':文件存在.

请注意您的分支名称可能与我的不同.您可以通过执行删除此锁定文件;

rm .git/refs/heads/[your-branch-name].lock
Run Code Online (Sandbox Code Playgroud)

希望这有助于某人.

  • 这就是帮助我的原因,其他答案对我没有任何帮助。 (3认同)

Mat*_*rby 14

好吧,我最终通过运行'$ git rm .git/index.lock'来让它工作......这很奇怪,因为我之前做了几次但没有用,但嘿计算机对吗?

  • 这里不需要使用`git rm`,只需`rm`即可.`index.lock`不是git要跟踪的文件. (5认同)

May*_*ish 13

如果您使用PowerShell,请使用rm(Remove-Item的别名):

rm -Force .git/index.lock


Ind*_*ake 10

如果您是Windows用户,则会出现错误'rm' is not recognized as an internal or external command。那是因为 rm 是一个 Linux 命令。因此,在 Windows 中,您可以使用下面的方法删除index.lock文件.git夹内的文件

del -f .git/index.lock
Run Code Online (Sandbox Code Playgroud)

  • 在 Windows 中对我不起作用!参数“f”无法识别。 (2认同)
  • 有时,如果您这样做,Windows 会给您一个**“无效开关”**错误。建议使用反斜杠 **(\\)** 而不是正斜杠 **(/)** 以避免这种情况。即 `del .git\index.lock` (2认同)

Man*_*awa 9

删除index.lock这里的文件:

<path to your repo>/.git/index.lock
Run Code Online (Sandbox Code Playgroud)

另外,如果您的存储库有子模块,index.lock也请删除此处的所有文件:

<path to your repo>/.git/modules/<path to your submodule>/index.lock
Run Code Online (Sandbox Code Playgroud)


cum*_*zor 8

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

1)删除index.lock文件(在.git/index.lock)

2) 删除您的Podfile.lock文件。

3)做一个新的 pod update

4) 尝试发出失败的 git 命令(在我的例子中是一个git add .)


小智 8

这也可能来自另一个使用 Git 的应用程序或插件。例如,源树。就我而言,似乎有一些与 Git 相关的进程卡在了 Sourcetree 中。因此,仅删除index.lock文件对我来说不起作用。我要删除项目目录中.git文件夹中的 sourcetreeconfig 并且它有效。

rm -rf .git/index.lock
rm -rf .git/sourcetreeconfig
Run Code Online (Sandbox Code Playgroud)


Aki*_*kif 7

它与上述方法类似,但在我的情况下,我有几种方法

.git/refs/heads/<branch_name>.lock
Run Code Online (Sandbox Code Playgroud)

并能够通过这种方式一次删除所有

find -name "*.lock" -exec xargs rm {} \;
Run Code Online (Sandbox Code Playgroud)


Ale*_*Sed 7

这发生在我身上,而当sourcetree不断告诉我锁定文件存在时,那里没有可供我删除的文件。因此,我刚刚签出了另一个分支,然后返回到原始分支,并注意到此更改解决了该问题。


小智 7

如果您遇到另一个 git 进程似乎正在此存储库中运行,请使用以下命令,例如由“git commit”打开的编辑器。请确保所有进程都已终止,然后重试。如果它仍然失败,则该存储库中的 git 进程可能早先崩溃了:手动删除文件以继续。

rm -f .git/index.lock

git reset 和 after reset 命令使用 git status、git add 和 git commit -a 或 git commit -m "your message", git push origin master。


fra*_*ein 7

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

例如,

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.
Run Code Online (Sandbox Code Playgroud)
rm -rf fullPathOftheFile
Run Code Online (Sandbox Code Playgroud)
rm -rf /Users/username/Development/project/.git/index.lock
Run Code Online (Sandbox Code Playgroud)


Vre*_*yan 6

对我来说,问题更简单,这是在源代码树中,所以我不确定它在多大程度上适用于常规解决方案,但我不小心选择了我的主分支尝试进行提交而不是我未提交的更改。

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

基本上,我在未提交的分支上开始提交,但不小心尝试在我的主分支上开始另一个提交。


Tar*_*rma 5

可能会发生您的分支已损坏创建新分支 git branch #check branch。我创建了一个新的分支并且正在工作。

branch -b "main"
git checkout -b "main"  #main is new branch
git add .
git commit -m "all files"
git remote add origin #**YOUR REPO**  https://github.com/tarun-techmarbles/wp-dump-sql-git-push.git
git push origin main  #push with new branch 
Run Code Online (Sandbox Code Playgroud)


Bra*_*ang 5

虽然上面有一个替代方案,但这并没有解决我的问题。就我而言,我删除了 ./zshrc 中的“git”插件并重新启动计算机,然后问题就消失了,我猜 zsh 插件做了一些与原始 git 命令冲突的事情。


Has*_*bal 5

我在 时收到此错误pod update。我通过删除CocoaPods目录index.lock中的文件解决了这个问题。.git

rm -f /Users/my_user_name/.cocoapods/repos/master/.git/index.lock
Run Code Online (Sandbox Code Playgroud)