如何修复失败的 git commit?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8198966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:21:42  来源:igfitidea点击:

How do I fix a failed git commit?

git

提问by mcgrailm

I am new to gitand was trying to commit, but I got stuck in what looked like viwhich I'm not familiar with. I managed to get out of it, but I think I got out the wrong way because my git status says "changes not staged," but I still can't try again. Could someone tell me what I can do to fix the still hanging process and commit my changes?

我是新手git并试图承诺,但我陷入了vi我不熟悉的事情中。我设法摆脱了它,但我认为我走错了路,因为我的 git 状态显示“未暂存更改”,但我仍然无法再试一次。有人能告诉我我能做些什么来修复仍然挂起的过程并提交我的更改吗?

here is the error

这是错误

fatal: Unable to create '/.git/index.lock': File exists.
If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.

not i took out the full path

不是我拿出了完整的路径

As always thanks for your help.

一如既往地感谢您的帮助。

采纳答案by Platinum Azure

Assuming you're not doing anything with git at the moment (i.e., not doing a push or pull or running a git script in the repository, for any reason), you could just remove the lock file manually and try again.

假设您目前没有对 git 执行任何操作(即,出于任何原因,没有在存储库中执行推送或拉取或运行 git 脚本),您可以手动删除锁定文件并重试。

Also, git expects a "commit message" describing your changes. Assuming you don't want an editor to open, you can provide an inline message using the -moption:

此外,git 需要一个“提交消息”来描述您的更改。假设您不想打开编辑器,您可以使用以下-m选项提供内联消息:

git commit -am "Changed this, that, and the other thing"

回答by Suhail Taj

Removing index.lockfile manually from .git directory worked.

从 .git 目录手动删除index.lock文件有效。

or

或者

From command line:

从命令行:

$ rm -rf .git/index.lock

Note:Make sure that only one indexfile exist on .git directory

注意:确保.git目录下只有一个索引文件

回答by VonC

Note the message will improve and be more explicit with git 2.9 (June 2016), in order to invite you to consider all the causes beforeremoving that lock yourself.

请注意,该消息将在 git 2.9(2016 年 6 月)中改进并更加明确,以便邀请您自己删除该锁之前考虑所有原因。

See commit aed7480, commit 3030c29(01 Mar 2016) by Matthieu Moy (moy).
Helped-by: Moritz Neeb (zormit).
(Merged by Junio C Hamano -- gitster--in commit 3b8c4b7, 03 Apr 2016)

请参阅Matthieu Moy ( ) 的commit aed7480commit 3030c29(2016 年 3 月 1 日。 帮助者:Moritz Neeb ( )(由Junio C Hamano合并-- --in commit 3b8c4b7, 03 Apr 2016)moy
zormit
gitster

lockfile: improve error message when lockfile exists

A common mistake leading a user to see this message is to launch "git commit", let the editor open (and forget about it), and try again to commit.

The previous message was going too quickly to "a git process crashed" and to the advice "remove the file manually".

This patch modifies the message in two ways:

  • first, it considers that "another process is running" is the norm, not the exception,
  • and it explicitly hints the user to look at text editors.

The message is 2 lines longer, but this is not a problem since experienced users do not see the message often.

锁文件:当锁文件存在时改进错误信息

导致用户看到此消息的常见错误是启动“ git commit”,让编辑器打开(然后忘记它),然后再次尝试提交。

之前的消息对于“git 进程崩溃”和“手动删除文件”的建议来说太快了。

此补丁以两种方式修改消息:

  • 首先,它认为“另一个进程正在运行”是常态,而不是例外,
  • 它明确提示用户查看文本编辑器。

该消息长了 2 行,但这不是问题,因为有经验的用户不会经常看到该消息。

回答by Mina Gabriel

mine was solved with both answers from Platinum Azurethen Suhail Taj

矿用来自两个答案解决白金天青然后Suhail泰姬陵

git commit -am "Changed this, that, and the other thing"

Then

然后

$ rm -rf .git/index.lock