11

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 repo has no commits (almost as if the repo was never created). Investigating this issue, I tried to clone the repo, and it gave me some weird errors I've never seen:

error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index .git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
error: non-monotonic index C:/Temp/N1/Netduino/.git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
fatal: unable to read tree cc90183a1571664f80712c0376f59afeb681303f

I have searched Google about this issue, and there's also another question on StackOverlow regarding this issue but it remains unanswered (this question). Anyone able to shed light on this issue? Thanks

Community
  • 1
  • 1
Anshul
  • 1,302
  • 3
  • 15
  • 36

2 Answers2

9

I was searching for info in this kind of non-monotonic error and found this link: http://git.661346.n2.nabble.com/Error-non-monotonic-index-after-failed-recursive-quot-sed-quot-command-td7575014.html

TL;DR: you remove the non-monotonic index and then reindex it. In Linux it would be:

> rm .git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.idx
> git index-pack .git/objects/pack/pack-29a18084cf61cd0322a6e9cfd485ce0977348c53.pack 

After this I had to run some git gc --prune=now and git remote prune origin, but I had done some other operations before, so I may have spoiled my repo.

Yun
  • 3,056
  • 6
  • 9
  • 28
Brenes
  • 311
  • 3
  • 6
5

(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:

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
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • When you say clone another fork, is that the same as cloning the repo? I'm getting these above errors when I try to clone the repo. And in step 2, to restore my local modifications would be to just "Reset File Changes" in Git Extensions? Thanks – Anshul Jul 23 '12 at 00:07
  • @Anshul Your repo has been copied (forked) multiple times on Github. Try to clone one of those other repos and see if the issue persists. – VonC Jul 23 '12 at 03:45
  • I'm not using GitHub, this is all on my personal computer. So if I understand you correctly, I should just take a copy of one of my other repositories and just use that? Essentially, delete my old broken repo and replace it with a new cloned one? Thanks – Anshul Jul 23 '12 at 14:04
  • @Anshul yes, a local copy, or you can clone one of the GitHub repo as well (even if you don't use GitHub for storing new commits) – VonC Jul 23 '12 at 14:12
  • Yes, this was the solution I was eventually going to resort to as well. I tried it and it worked. I cloned one of my other personal repos and made that my central repo. Thank you for the help! – Anshul Jul 24 '12 at 20:36