Why is git erroring with 'Assertion failed' on git add .?

后端 未结 4 1094
北荒
北荒 2021-02-02 12:32

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 in

相关标签:
4条回答
  • 2021-02-02 12:53

    I got this problem too,Here is my way to fix this:

    1. delete the .git folder in the submodule folder(if you did this before, go 2)
    2. then excute follow command, directory is your submodule folder git rm --cached directory git add directory
    3. then you can upload this folder like others
    0 讨论(0)
  • 2021-02-02 12:56

    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 pathspec is part of the submodule.

    The following Git patch from Stefan Beller fixes that problem:

    --- 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).

    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.

    Then try adding the files again.


    See also:

    • [PATCH] pathspec: give better message for submodule related pathspec error
    • Re: [PATCH] pathspec: adjust prefixlen after striping trailing slash
    • assert failed in submodule edge case,
    • "item->nowildcard_len" in Google.
    0 讨论(0)
  • 2021-02-02 13:02

    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

    was to rename directory and then add it again.

    0 讨论(0)
  • 2021-02-02 13:04

    Not sure exactly what's happening but I was in the same situation

    1. I moved one git repo inside another
    2. deleted the .git dir thinking it would become a regular subdir
    3. tried to git add -A .
    4. got the weird error message

    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.

    0 讨论(0)
提交回复
热议问题