Rilcon42 Rilcon42 - 3 months ago 14
Git Question

git blob fails on push

I have no clue what I did to my git repo, can someone explain what went wrong?
My first command was:

git commit -m "another commit" .
git push -u origin master
which failed. then I tried
git fsck --full
and removing files based on another SO post which didnt fix my issue. At this point Im not even sure what to google, any suggestions?

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ git fsck --full
Checking object directories: 100% (256/256), done.
error: bad object header1403/1404)
error: unknown object type -1 at offset 12 in .git/objects/pack/pack-627dd5f8d19a0d3289d2dc5bb37e776aa845ae2f.pack
error: cannot unpack 7884ba2578c7535a2e3b70d410f0286bd2e0016f from .git/objects/pack/pack-627dd5f8d19a0d3289d2dc5bb37e776aa845ae2f.pack at offset 12
Checking objects: 100% (1404/1404), done.

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ rm -f .git/objects/pack/pack-627dd5f8d19a0d3289d2dc5bb37e776aa845ae2f.pack

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ git fsck --full
Checking object directories: 100% (256/256), done.
Checking objects: 100% (1403/1403), done.
missing blob 7884ba2578c7535a2e3b70d410f0286bd2e0016f

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ git commit -m "trying again" .
error: invalid object 100644 7884ba2578c7535a2e3b70d410f0286bd2e0016f for '3212703ED955F10C7534BE8497B221F4/tester/history/EURUSD1440_0.fxt'
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working directory clean

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ git push -u origin master
Counting objects: 70, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (65/65), done.
fatal: unable to read 7884ba2578c7535a2e3b70d410f0286bd2e0016f
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
fatal: write error: Bad file descriptor
error: failed to push some refs to 'https://yzpaul@bitbucket.org/yzpaul/misc-scripts.git'

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ git fsck --full
Checking object directories: 100% (256/256), done.
Checking objects: 100% (1403/1403), done.
missing blob 7884ba2578c7535a2e3b70d410f0286bd2e0016f

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ git reflog expire --expire=now --all

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ git push -u origin master
Counting objects: 70, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (65/65), done.
fatal: unable to read 7884ba2578c7535a2e3b70d410f0286bd2e0016f
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
fatal: write error: Bad file descriptor
error: failed to push some refs to 'https://yzpaul@bitbucket.org/yzpaul/misc-scripts.git'

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ git hash-object -w 7884ba2578c7535a2e3b70d410f0286bd2e0016f
fatal: Cannot open '7884ba2578c7535a2e3b70d410f0286bd2e0016f': No such file or directory

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ git prune

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ git prune --expire=now

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ git push -u origin master
Counting objects: 70, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (65/65), done.
fatal: unable to read 7884ba2578c7535a2e3b70d410f0286bd2e0016f
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
fatal: write error: Bad file descriptor
error: failed to push some refs to 'https://yzpaul@bitbucket.org/yzpaul/misc-scripts.git'

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ git push -u origin master --force
Counting objects: 70, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (65/65), done.
fatal: unable to read 7884ba2578c7535a2e3b70d410f0286bd2e0016f
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
fatal: write error: Bad file descriptor
error: failed to push some refs to 'https://yzpaul@bitbucket.org/yzpaul/misc-scripts.git'

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ git gc --prune --agressive
error: unknown option `agressive'
usage: git gc [<options>]

-q, --quiet suppress progress reporting
--prune[=<date>] prune unreferenced objects
--aggressive be more thorough (increased runtime)
--auto enable auto-gc mode
--force force running gc even if there may be another gc running


king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$ git gc --prune=8-12-2016
Counting objects: 1418, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (748/748), done.
fatal: unable to read 7884ba2578c7535a2e3b70d410f0286bd2e0016f
error: failed to run repack

king@DESKTOP-US7LR7D MINGW64 ~/Desktop/_REPOS/misc (master)
$

Answer

Well you nuked an object with the SHA-1 name 7884ba2578c7535a2e3b70d410f0286bd2e0016f from your repository with your second command.

The rest of the commands are just executing random crap from the internets.

Please take my advice: as soon as you hit a supposedly serious problem—like that one indicated by the first command you showed—just backup the whole repository by physically copying its entire directory somewhere else—preferably on some other physical storage (because the H/W storage under the repository might be failing). Having done that, calm down and reach for the help. Please don't just try random crap like the advices to expire the reflog (utter nonsense).

OK, back to the case. Since you've nuked that object, you will unlikely be able to proceed until you recover it. It worth repeating: Git stores all its objects in a single database (located under the ".git" directory), and this database is shared by all "things" which refer to the history kept there. So no matter which exactly Git command failed to locate the object, you can be sure it's not in the database and you have to obtain it from elsewhere.

Now there are two possibilities:

  1. That object was a part of some past history.

    If yes, then there is a chance you'll be able to recover it from a repository's replica hosted elsewhere.

  2. It's was part of some recent history not pushed anywhere.

    If yes, you're pretty much at a loss since you've just physically deleted a part of the object database with your second command.

So. The first thing to try is to clone a replica of this repository from somewhere else and then try running

$ git cat-file -t 7884ba2578c7535a2e3b70d410f0286bd2e0016f

if it prints you the type of that object, all is well and you can proceed recovering it by running

$ git cat-file <type> 7884ba2578c7535a2e3b70d410f0286bd2e0016f > foo

where <type> is the object's type obtained on the previous step (there are three of them: blob, tree and commit). The last two words use the shell redirection to place the output contents into a file named "foo".

After that, grab that file "foo", copy it into your source repository and run

$ git hash-object -w foo

there: this command will extract the contents from the file and place it into the repository—resulting in the object with the given SHA-1 hash be available in the object store.

You can now re-run git fsck --full.


Still, even if that will work (it should) I still feel uneasy about you having had removed a so-called "pack file". Pack files typically contain large amounts of past history so you supposedly removed quite a lot of stuff.

To fix that, I'd try to clone an available replica and then fetch there the unpushed commits from your source repository, and then I would start to use this clone in place of the original repository.

Comments