【发布时间】:2021-02-15 21:54:13
【问题描述】:
我做到了:
git add --all # success
git status # saw all my changes in staged area
git commit -am wip # failed because of some hooks (it was expected behavior)
# fixed the issue which causes the hooks to fail
然后:
~ git add --all
fatal: Unable to create '/Users/stavalfi/projects/dancer/.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 /Users/stavalfi/projects/dancer/.git/index.lock
git add --all
git status
最后一个命令只显示了我添加的新文件。
我丢失了所有跟踪文件中的所有更改。
怎么办?
【问题讨论】:
-
你确定他们丢失了吗?据我了解,您的第三个命令是提交修改,所以也许您在上次提交中的更改......
-
万一他们迷路了,这个答案可能会有所帮助:stackoverflow.com/a/42861993/5935112
-
这对您目前的情况没有帮助,但我建议避免
git commit -a。 (-m选项很好,您应该避免使用-a选项。) -
这有点难以理解并且它往往会与一些预提交挂钩进行不良交互。在这种情况下,我会担心这就是您的文件被破坏的方式。这并不是你的错——很可能,编写预提交钩子的人不知道
-a选项以及它是如何工作的,并且他们将错误放入了你遇到的钩子中。但是您可以通过避免选项来避免错误! -
看起来赫斯基本身只是一个框架。它包括一个例子/¿默认?运行
npm test的预提交,我认为 应该 是安全的,但我不是 npm 专家。但它也允许你添加更多的钩子,每个钩子的每个作者都需要了解 Git 规则,所以一些第三方插件可能是这里的罪魁祸首。
标签: git