Git error “non-monotonic index”

后端 未结 2 1953
感动是毒
感动是毒 2021-02-20 11:36

My git setup has a central repository to which I push. Today I decided to look at the central repository using Git Extensions, and it said that the rep

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-20 12:12

    (not a complete answer, but at least some clues, and a workaround)

    That error message comes from the sha1_file.c, method check_packed_git_idx(),

    nr = 0;
    index = idx_map;
    if (version > 1)
      index += 2; /* skip index header */
    for (i = 0; i < 256; i++) {
      uint32_t n = ntohl(index[i]);
      if (n < nr) {
        munmap(idx_map, idx_size);
        return error("non-monotonic index %s", path);
      }
      nr = n;
    }
    

    with ntohl function being:

    The ntohl function converts a u_long from TCP/IP network order to host byte order (which is little-endian on Intel processors).

    The ntohl function returns the value supplied in the netlong parameter with the byte order reversed. If netlong is already in host byte order, then this function will reverse it. It is up to the application to determine if the byte order must be reversed.

    The ntohl function takes a 32-bit number in TCP/IP network byte order (the AF_INET or AF_INET6 address family) and returns a 32-bit number in host byte order.

    It is called by:

    • open_pack_index(), and
    • parse_pack_index()

    See the structure of a pack file in the SO question "Is the git binary diff algorithm (delta storage) standardized?":

    pack file structure

    The first one is also called by builtin/fsck.c, so you can try a git fsck --full --progress, in order to check if you have a local corruption of your pack files, or if it actually is a remote repo issue.
    Make sure you can replicate the issue on different OS and/or different version of Git.

    The usual workaround, for a (here "Netduino") repo which seems to be forked around on GitHub, is to:

    • clone another fork,
    • restore one's own local modification from the corrupt repo, add them and commit them
    • push --force back to one's own fork, in order to erase/reset the remote history by one with can be packed correctly

提交回复
热议问题