{"thread":{"id":"32623","subject":"Error:non-monotonic index after failed recursive \"sed\" command","startedAt":"2013-01-14T11:40:31Z","lastAt":"2013-01-15T00:54:46Z","messageCount":9,"participants":["George Karpenkov","Matthieu Moy","John Keeping","Johannes Sixt","Junio C Hamano","Philip Oakley"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"206791","messageId":"CAMoGvRKkSZqcoGtiebu6tuPndzOjQ1=JgQHb+iusAHpUbA2HbA@mail.gmail.com","threadId":"32623","inReplyTo":null,"subject":"Error:non-monotonic index after failed recursive \"sed\" command","fromName":"George Karpenkov","fromEmail":"george@metaworld.ru","sentAt":"2013-01-14T11:40:31Z","receivedAt":"2013-01-14T11:40:31Z","isPatch":false,"sender":{"key":"george@metaworld.ru","avatar":null},"body":"Hi All,\n\nI've managed to corrupt my very valuable repository with a recursive\nsed which went wrong.\nI wanted to convert all tabs to spaces with the following command:\n\nfind ./ -name '*.*' -exec sed -i 's/\\t/    /g' {} \\;\n\nI think that has changed not only the files in the repo, but the data\nfiles in .git directory itself. As a result, my index became\ncorrupted, and almost every single command dies:\n\n> git log\nerror: non-monotonic index\n.git/objects/pack/pack-314b1944adebea645526b6724b2044c1313241f5.idx\nerror: non-monotonic index\n.git/objects/pack/pack-75c95b0defe1968b61e4f4e1ab7040d35110bfdc.idx\n...\nerror: non-monotonic index\n.git/objects/pack/pack-3da0da48d05140b55f4af1cf87c55a2d7898bdd5.idx\nfatal: bad object HEAD\n\nOutput for git fsck is even worse:\n\n> git fsck\nerror: non-monotonic index\n.git/objects/pack/pack-434f8445672a92f123accffce651bdb693bd8fcb.idx\n...\nerror: non-monotonic index\n.git/objects/pack/pack-0c9d5ae4e2b46dd78dace7533adf6cdfe10326ef.idx\nerror: non-monotonic index\n.git/objects/pack/pack-e8bd5c7f85e96e7e548a62954a8f7c7f223ba9e0.idx\nSegmentation fault (core dumped)\n\nAny advice? I've lost about 2 weeks worth of work.\nIs there anything better I can try to do other then trying to\nreconstruct the data manually from git blobs?\n"},{"id":"206792","messageId":"vpq38y42clj.fsf@grenoble-inp.fr","threadId":"32623","inReplyTo":"CAMoGvRKkSZqcoGtiebu6tuPndzOjQ1=JgQHb+iusAHpUbA2HbA@mail.gmail.com","subject":"Re: Error:non-monotonic index after failed recursive \"sed\" command","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-01-14T12:06:16Z","receivedAt":"2013-01-14T12:06:16Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"George Karpenkov <george@metaworld.ru> writes:\n\n> Hi All,\n>\n> I've managed to corrupt my very valuable repository with a recursive\n> sed which went wrong.\n> I wanted to convert all tabs to spaces with the following command:\n>\n> find ./ -name '*.*' -exec sed -i 's/\\t/    /g' {} \\;\n\nClearly, this is a dangerous command as it impacts .git/. However, Git\npartially protects you from this kind of error, since object files and\npack files are read-only by default.\n\nMy obvious first advice is: make backups of your corrupted repository.\nYes, I said backup_s_, better safe than sorry.\n\nThen, the errors you get are in *.idx files, which are basically index\nfor pack files, for quicker access. You can try removing these files,\nand then running \"git index-pack\" on each pack file, like\n\n$ rm .git/objects/pack/pack-*.idx\n$ git index-pack .git/objects/pack/pack-4745076928ca4df932a3727b8cc25e83574560bb.pack                        \n4745076928ca4df932a3727b8cc25e83574560bb                                                              \n$ git index-pack .git/objects/pack/pack-c74a6514f653d0269cdcdf9c1c102d326706bbda.pack\nc74a6514f653d0269cdcdf9c1c102d326706bbda\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"206793","messageId":"20130114121247.GS4574@serenity.lan","threadId":"32623","inReplyTo":"vpq38y42clj.fsf@grenoble-inp.fr","subject":"Re: Error:non-monotonic index after failed recursive \"sed\" command","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2013-01-14T12:12:47Z","receivedAt":"2013-01-14T12:12:47Z","isPatch":false,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"On Mon, Jan 14, 2013 at 01:06:16PM +0100, Matthieu Moy wrote:\n> George Karpenkov <george@metaworld.ru> writes:\n>> I've managed to corrupt my very valuable repository with a recursive\n>> sed which went wrong.\n>> I wanted to convert all tabs to spaces with the following command:\n>>\n>> find ./ -name '*.*' -exec sed -i 's/\\t/    /g' {} \\;\n> \n> Clearly, this is a dangerous command as it impacts .git/. However, Git\n> partially protects you from this kind of error, since object files and\n> pack files are read-only by default.\n> \n> My obvious first advice is: make backups of your corrupted repository.\n> Yes, I said backup_s_, better safe than sorry.\n\nHaving backed up the corrupt state, another option is to just try\nrunning the reverse command:\n\nfind .git -name '*.*' -exec sed -i 's/    /\\t/g' {} \\;\n\nI had a quick grep over some pack indices here and '    ' doesn't occur\nin any of mine whereas '\\t' is very common so you may find that the only\n'    ' sequences are the ones you introduced.\n\n\nJohn\n"},{"id":"206794","messageId":"50F3F852.8060800@viscovery.net","threadId":"32623","inReplyTo":"CAMoGvRKkSZqcoGtiebu6tuPndzOjQ1=JgQHb+iusAHpUbA2HbA@mail.gmail.com","subject":"Re: Error:non-monotonic index after failed recursive \"sed\" command","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2013-01-14T12:21:38Z","receivedAt":"2013-01-14T12:21:38Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 1/14/2013 12:40, schrieb George Karpenkov:\n> I've managed to corrupt my very valuable repository with a recursive\n> sed which went wrong.\n> I wanted to convert all tabs to spaces with the following command:\n> \n> find ./ -name '*.*' -exec sed -i 's/\\t/    /g' {} \\;\n> \n> I think that has changed not only the files in the repo, but the data\n> files in .git directory itself. As a result, my index became\n> corrupted, and almost every single command dies:\n> \n>> git log\n> error: non-monotonic index\n> ..git/objects/pack/pack-314b1944adebea645526b6724b2044c1313241f5.idx\n> error: non-monotonic index\n> ..git/objects/pack/pack-75c95b0defe1968b61e4f4e1ab7040d35110bfdc.idx\n> ....\n> error: non-monotonic index\n> ..git/objects/pack/pack-3da0da48d05140b55f4af1cf87c55a2d7898bdd5.idx\n> fatal: bad object HEAD\n> \n> Output for git fsck is even worse:\n> \n>> git fsck\n> error: non-monotonic index\n> ..git/objects/pack/pack-434f8445672a92f123accffce651bdb693bd8fcb.idx\n> ....\n> error: non-monotonic index\n> ..git/objects/pack/pack-0c9d5ae4e2b46dd78dace7533adf6cdfe10326ef.idx\n> error: non-monotonic index\n> ..git/objects/pack/pack-e8bd5c7f85e96e7e548a62954a8f7c7f223ba9e0.idx\n> Segmentation fault (core dumped)\n> \n> Any advice? I've lost about 2 weeks worth of work.\n> Is there anything better I can try to do other then trying to\n> reconstruct the data manually from git blobs?\n\nFirst things first: MAKE A COPY OF THE CURRENT STATE of the repository,\nincluding the worktree, so that you have something to go back to if things\nget worse later. (At the very least, we want to debug the segfault that we\nsee above.)\n\nSo far that's all I can say about your case. Everything that follows is\njust a shot in the dark, and others may have better ideas. Also, look\nhere:\nhttps://github.com/gitster/git/blob/master/Documentation/howto/recover-corrupted-blob-object.txt\n\nYou can remove the *.idx files, because they do not carry essential\ninformation. Now try git fsck; git repack.\n\nTry the reverse edit:\n\n find .git -name '*.*' -exec sed -i 's/    /\\t/g' {} \\;\n\nRemove .git/index; it can be reconstructed (of course, assuming you\nstarted all this with a clean index; if not, you lose the staged changes).\n\n-- Hannes\n"},{"id":"206825","messageId":"7v622zbn3s.fsf@alter.siamese.dyndns.org","threadId":"32623","inReplyTo":"50F3F852.8060800@viscovery.net","subject":"Re: Error:non-monotonic index after failed recursive \"sed\" command","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-01-14T19:06:47Z","receivedAt":"2013-01-14T19:06:47Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j.sixt@viscovery.net> writes:\n\n> Am 1/14/2013 12:40, schrieb George Karpenkov:\n>> I've managed to corrupt my very valuable repository with a recursive\n>> sed which went wrong.\n>> I wanted to convert all tabs to spaces with the following command:\n>> \n>> find ./ -name '*.*' -exec sed -i 's/\\t/    /g' {} \\;\n>> \n>> I think that has changed not only the files in the repo, but the data\n>> files in .git directory itself. As a result, my index became\n>> corrupted, and almost every single command dies:\n>> \n>>> git log\n>> error: non-monotonic index\n>> ..git/objects/pack/pack-314b1944adebea645526b6724b2044c1313241f5.idx\n>> error: non-monotonic index\n>> ..git/objects/pack/pack-75c95b0defe1968b61e4f4e1ab7040d35110bfdc.idx\n>> ....\n> ...\n> Try the reverse edit:\n>\n>  find .git -name '*.*' -exec sed -i 's/    /\\t/g' {} \\;\n>\n> Remove .git/index; it can be reconstructed (of course, assuming you\n> started all this with a clean index; if not, you lose the staged changes).\n\nEverybody seems to be getting an impression that .idx is the only\nthing that got corrupt.  Where does that come from?\n\nI do not see anything that prevents the original command line from\ntouching *.pack files.  Loose objects may have been left unmolested\nas their names do not match '*.*', though.\n"},{"id":"206828","messageId":"vpqobgrpoh7.fsf@grenoble-inp.fr","threadId":"32623","inReplyTo":"7v622zbn3s.fsf@alter.siamese.dyndns.org","subject":"Re: Error:non-monotonic index after failed recursive \"sed\" command","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-01-14T19:13:24Z","receivedAt":"2013-01-14T19:13:24Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Everybody seems to be getting an impression that .idx is the only\n> thing that got corrupt.  Where does that come from?\n\nIt's the only thing that appear in the error message. This does not\nimply that it is the only corrupt thing, but gives a little hope that it\nmay still be the case.\n\nActually, I thought the \"read-only\" protection should have protected\nfiles in object/ directory, but a little testing shows that \"sed -i\"\ngladly accepts to modify read-only files (technically, it does not\nmodify it, but creates a temporary file with the new content, and then\nrenames it to the new location). So, the hope that pack files are\nuncorrupted is rather thin unfortunately.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"206850","messageId":"CAMoGvRKMwP_JBvNNWoN=m9AX3MP9xVgBUwxELHtry_-8Um8WKQ@mail.gmail.com","threadId":"32623","inReplyTo":"vpqobgrpoh7.fsf@grenoble-inp.fr","subject":"Re: Error:non-monotonic index after failed recursive \"sed\" command","fromName":"George Karpenkov","fromEmail":"george@metaworld.ru","sentAt":"2013-01-14T22:57:09Z","receivedAt":"2013-01-14T22:57:09Z","isPatch":false,"sender":{"key":"george@metaworld.ru","avatar":null},"body":"Thanks everyone!\n\nProgress so far:\n\nAfter executing reverse sed command:\nfind .git -name '*.*' -exec sed -i 's/    /\\t/g' {} \\;\n\nAnd trying to switch the branch I get:\n\n> git checkout X\n\nerror: failed to read object 51a980792f26875d00acb79a19f043420f542cfa\nat offset 41433013 from\n.git/objects/pack/pack-8d629235ee9fec9c6683d42e3edb21a1b0f6e027.pack\nfatal: packed object 51a980792f26875d00acb79a19f043420f542cfa (stored\nin .git/objects/pack/pack-\n8d629235ee9fec9c6683d42e3edb21a1b0f6e027.pack) is corrupt\n\nSo the actual .pack file is corrupt, unfortunately.\n\nOn Tue, Jan 15, 2013 at 6:13 AM, Matthieu Moy\n<Matthieu.Moy@grenoble-inp.fr> wrote:\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n>> Everybody seems to be getting an impression that .idx is the only\n>> thing that got corrupt.  Where does that come from?\n>\n> It's the only thing that appear in the error message. This does not\n> imply that it is the only corrupt thing, but gives a little hope that it\n> may still be the case.\n>\n> Actually, I thought the \"read-only\" protection should have protected\n> files in object/ directory, but a little testing shows that \"sed -i\"\n> gladly accepts to modify read-only files (technically, it does not\n> modify it, but creates a temporary file with the new content, and then\n> renames it to the new location). So, the hope that pack files are\n> uncorrupted is rather thin unfortunately.\n>\n> --\n> Matthieu Moy\n> http://www-verimag.imag.fr/~moy/\n"},{"id":"206853","messageId":"B10A5C9F770D48C9958F240D59B1A400@PhilipOakley","threadId":"32623","inReplyTo":"CAMoGvRKMwP_JBvNNWoN=m9AX3MP9xVgBUwxELHtry_-8Um8WKQ@mail.gmail.com","subject":"Re: Error:non-monotonic index after failed recursive \"sed\" command","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.org","sentAt":null,"receivedAt":"2013-01-14T23:43:34Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"From: \"George Karpenkov\" <george@metaworld.ru>\nSent: Monday, January 14, 2013 10:57 PM\n> Thanks everyone!\n>\n> Progress so far:\n>\n> After executing reverse sed command:\n> find .git -name '*.*' -exec sed -i 's/    /\\t/g' {} \\;\n\nHave you counted how many substitutions there are in the pack file(s). \nIt may be sufficiently small that you can  simply try all the possible \ncombinations of fwd and reverse substitutions. Even if it takes a few \ndays the computer won't get bored ;-)\n\n>\n> And trying to switch the branch I get:\n>\n>> git checkout X\n>\n> error: failed to read object 51a980792f26875d00acb79a19f043420f542cfa\n> at offset 41433013 from\n> .git/objects/pack/pack-8d629235ee9fec9c6683d42e3edb21a1b0f6e027.pack\n> fatal: packed object 51a980792f26875d00acb79a19f043420f542cfa (stored\n> in .git/objects/pack/pack-\n> 8d629235ee9fec9c6683d42e3edb21a1b0f6e027.pack) is corrupt\n>\n> So the actual .pack file is corrupt, unfortunately.\n>\n> On Tue, Jan 15, 2013 at 6:13 AM, Matthieu Moy\n> <Matthieu.Moy@grenoble-inp.fr> wrote:\n>> Junio C Hamano <gitster@pobox.com> writes:\n>>\n>>> Everybody seems to be getting an impression that .idx is the only\n>>> thing that got corrupt.  Where does that come from?\n>>\n>> It's the only thing that appear in the error message. This does not\n>> imply that it is the only corrupt thing, but gives a little hope that \n>> it\n>> may still be the case.\n>>\n>> Actually, I thought the \"read-only\" protection should have protected\n>> files in object/ directory, but a little testing shows that \"sed -i\"\n>> gladly accepts to modify read-only files (technically, it does not\n>> modify it, but creates a temporary file with the new content, and \n>> then\n>> renames it to the new location). So, the hope that pack files are\n>> uncorrupted is rather thin unfortunately.\n>>\n>> --\n>> Matthieu Moy\n>> http://www-verimag.imag.fr/~moy/\n> --\n"},{"id":"206875","messageId":"CAMoGvRJhwqRqdV=-AAqbjrDzcL2_zPUfaEhrQuHS+DjD3X9qTw@mail.gmail.com","threadId":"32623","inReplyTo":"B10A5C9F770D48C9958F240D59B1A400@PhilipOakley","subject":"Re: Error:non-monotonic index after failed recursive \"sed\" command","fromName":"George Karpenkov","fromEmail":"george@metaworld.ru","sentAt":"2013-01-15T00:54:46Z","receivedAt":"2013-01-15T00:54:46Z","isPatch":false,"sender":{"key":"george@metaworld.ru","avatar":null},"body":"Happy ending!\n\nTurns out i have actually made a backup 3 days ago.\n\nMy other work was on a branch + in a stash. Commits done on a branch\nwere already present in a backup.\nI was able to get the stash working by copying corrupted .pack files\nfrom the backup, luckily all the new work wasn't packed yet.\n\nSo i've just verified the log messages to see that no new commits were\nmade, created a patch from the corrupted git repo of the stash,\napplied it on the backup, and wo-hooo, everything worked.\nAnd then I've pushed to origin to avoid such silliness in the future.\n\nThanks and Regards,\nGeorge\n\nOn Tue, Jan 15, 2013 at 10:45 AM, Philip Oakley <philipoakley@iee.org> wrote:\n> From: \"George Karpenkov\" <george@metaworld.ru>\n> Sent: Monday, January 14, 2013 10:57 PM\n>\n>> Thanks everyone!\n>>\n>> Progress so far:\n>>\n>> After executing reverse sed command:\n>> find .git -name '*.*' -exec sed -i 's/    /\\t/g' {} \\;\n>\n>\n> Have you counted how many substitutions there are in the pack file(s). It\n> may be sufficiently small that you can  simply try all the possible\n> combinations of fwd and reverse substitutions. Even if it takes a few days\n> the computer won't get bored ;-)\n>\n>>\n>> And trying to switch the branch I get:\n>>\n>>> git checkout X\n>>\n>>\n>> error: failed to read object 51a980792f26875d00acb79a19f043420f542cfa\n>> at offset 41433013 from\n>> .git/objects/pack/pack-8d629235ee9fec9c6683d42e3edb21a1b0f6e027.pack\n>> fatal: packed object 51a980792f26875d00acb79a19f043420f542cfa (stored\n>> in .git/objects/pack/pack-\n>> 8d629235ee9fec9c6683d42e3edb21a1b0f6e027.pack) is corrupt\n>>\n>> So the actual .pack file is corrupt, unfortunately.\n>>\n>> On Tue, Jan 15, 2013 at 6:13 AM, Matthieu Moy\n>> <Matthieu.Moy@grenoble-inp.fr> wrote:\n>>>\n>>> Junio C Hamano <gitster@pobox.com> writes:\n>>>\n>>>> Everybody seems to be getting an impression that .idx is the only\n>>>> thing that got corrupt.  Where does that come from?\n>>>\n>>>\n>>> It's the only thing that appear in the error message. This does not\n>>> imply that it is the only corrupt thing, but gives a little hope that it\n>>> may still be the case.\n>>>\n>>> Actually, I thought the \"read-only\" protection should have protected\n>>> files in object/ directory, but a little testing shows that \"sed -i\"\n>>> gladly accepts to modify read-only files (technically, it does not\n>>> modify it, but creates a temporary file with the new content, and then\n>>> renames it to the new location). So, the hope that pack files are\n>>> uncorrupted is rather thin unfortunately.\n>>>\n>>> --\n>>> Matthieu Moy\n>>> http://www-verimag.imag.fr/~moy/\n>>\n>> --\n>\n>\n"}]}