xcode 为什么在 git add 上出现“断言失败”的 git 错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23205961/
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
Why is git erroring with 'Assertion failed' on git add .?
提问by user26270
I forked a repo, then cloned it to my Mac into a /YATC
directory. I had a previously-created Xcode project (TwitterTimeline) in another directory, which I copied into the /YATC directory
. I did git add .
in the /YATC directory, and only an empty TwitterTimeline directory was added to the repo. No other files were added. I later found out that there was already a .git
directory in TwitterTimeline. I think Xcode must have created that, although I don't recall ever asking it to.
我分叉了一个 repo,然后将它克隆到我的 Mac 到一个/YATC
目录中。我在另一个目录中有一个先前创建的 Xcode 项目 (TwitterTimeline),我将其复制到/YATC directory
. 我是git add .
在 /YATC 目录下做的,只有一个空的 TwitterTimeline 目录被添加到 repo 中。没有添加其他文件。后来我发现.git
TwitterTimeline 中已经有一个目录。我认为 Xcode 一定已经创建了它,尽管我不记得曾经要求它这样做。
Anyway, I deleted the TwitterTimeline/.git
directory. I went back up to /YATC
and tried to do git add .
there, and nothing happened. Meaning I immediately did git status
, and it said there was nothing to commit. Then I went down to the TwitterTimeline directory and did git add .
, and got the following:
无论如何,我删除了TwitterTimeline/.git
目录。我回到那里/YATC
并试图在git add .
那里做,但什么也没发生。这意味着我立即做了git status
,它说没有什么可提交的。然后我转到 TwitterTimeline 目录并执行git add .
,并得到以下内容:
Assertion failed: (item->nowildcard_len <= item->len && item->prefix <= item->len), function prefix_pathspec, file pathspec.c, line 308.
Abort trap: 6
What is this?
这是什么?
回答by Patrick Canfield
Not sure exactly what's happening but I was in the same situation
不确定到底发生了什么,但我处于同样的情况
- I moved one git repo inside another
- deleted the .git dir thinking it would become a regular subdir
- tried to
git add -A .
- got the weird error message
- 我将一个 git repo 移到另一个里面
- 删除了 .git 目录,认为它会成为一个常规的子目录
- 试着
git add -A .
- 收到奇怪的错误信息
I got around it by renaming the subdir, doing git add
from a parent dir, then renaming the subdir back to the original name. Somehow that seemed to get git back in a working state.
我通过重命名子目录来解决它,git add
从父目录开始,然后将子目录重命名回原始名称。不知何故,这似乎让 git 回到了工作状态。
回答by kenorb
Basically the problem is known and it usually affects submodules. It's not Git bug, but basically instead of assert you should see the proper error that specific pathspecis part of the submodule.
基本上问题是已知的,它通常会影响子模块。这不是 Git 错误,但基本上不是断言,您应该看到特定路径规范是子模块的一部分的正确错误。
The following Git patchfrom Stefan Beller fixes that problem:
以下来自 Stefan Beller 的Git补丁修复了这个问题:
--- a/pathspec.c
+++ b/pathspec.c
@@ -313,8 +313,23 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
}
/* sanity checks, pathspec matchers assume these are sane */
- assert(item->nowildcard_len <= item->len &&
- item->prefix <= item->len);
+ if (item->nowildcard_len > item->len ||
+ item->prefix > item->len) {
+ /* Historically this always was a submodule issue */
+ for (i = 0; i < active_nr; i++) {
+ struct cache_entry *ce = active_cache[i];
+ int ce_len = ce_namelen(ce);
+ int len = ce_len < item->len ? ce_len : item->len;
+ if (!S_ISGITLINK(ce->ce_mode))
+ continue;
+ if (!memcmp(ce->name, item->match, len))
+ die (_("Pathspec '%s' is in submodule '%.*s'"),
+ item->original, ce_len, ce->name);
+ }
+ /* The error is a new unknown bug */
+ die ("BUG: item->nowildcard_len > item->len || item->prefix > item->len)");
+ }
+
return magic;
}
One of the reason could be that the directory where you're adding the files is still registered as a submodule in the index, but actually it's not a valid git repository (e.g. it's missing .git
directory).
原因之一可能是您添加文件的目录仍然在索引中注册为子模块,但实际上它不是有效的 git 存储库(例如,它缺少.git
目录)。
So you should either:
所以你应该:
initialize and update your submodules by:
git submodule init git submodule update
Run from the parent directory where you had the error.
Make sure all non-initialized submodules have empty directories, so move any files out of there temporary.
or if you don't need this submodule, remove it:
git rm -f --cached subrepo
Run from the parent directory where you had the error.
通过以下方式初始化和更新您的子模块:
git submodule init git submodule update
从出现错误的父目录运行。
确保所有未初始化的子模块都有空目录,因此将所有文件临时移出。
或者,如果您不需要此子模块,请将其删除:
git rm -f --cached subrepo
从出现错误的父目录运行。
Then try adding the files again.
然后再次尝试添加文件。
See also:
也可以看看:
回答by F.Anne
I got this problem too,Here is my way to fix this:
我也遇到了这个问题,我的解决方法如下:
- delete the .git folder in the submodule folder(if you did this before, go 2)
- then excute follow command, directory is your submodule folder
git rm --cached directory git add directory
- then you can upload this folder like others
- 删除子模块文件夹中的 .git 文件夹(如果您之前这样做过,请转到 2)
- 然后执行follow命令,目录是你的子模块文件夹
git rm --cached directory git add directory
- 然后你可以像其他人一样上传这个文件夹
回答by Adeerlike
The only way i was able to get around this error, after
在此之后,我能够解决此错误的唯一方法
- Deleting the .git folder
git deinit
git rm
- going over these links git fatal pathspec submodule, deleting local repo, assert failed in submodule
- 删除 .git 文件夹
git deinit
git rm
- 查看这些链接 git fatal pathspec 子模块, 删除本地存储库, 在子模块中断言失败
was to rename directory and then add it again.
是重命名目录,然后再次添加它。