git blob 推送失败

git blob fails on push

我不知道我对 git 存储库做了什么,有人能解释一下哪里出了问题吗? 我的第一个命令是:git commit -m "another commit" . git push -u origin master 失败了。然后我尝试 git fsck --full 并根据另一个 SO post 删除文件,但没有解决我的问题。在这一点上,我什至不确定要做什么 google,有什么建议吗?

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

一般来说,修复损坏的存储库并不容易,但在这种情况下,您会遗漏一个 blob:

missing blob 7884ba2578c7535a2e3b70d410f0286bd2e0016f

您可以尝试从另一个存储库(例如从远程)复制对象“.git/objects/78/84ba...”并将其粘贴到您的本地存储库中。

如果不是这种情况,您可能会拉到新的存储库并重新访问之前的提交:

git checkout previous_commit_hash .

然后将当前工作的 space 文件复制到它并再次提交。

好吧,您使用第二个命令从您的存储库中删除了一个具有 SHA-1 名称 7884ba2578c7535a2e3b70d410f0286bd2e0016f 的对象。

其余命令只是执行来自互联网的随机废话。

请采纳我的建议:一旦遇到所谓的严重问题(例如您显示的第一个命令所指示的问题),只需 备份整个存储库 物理 将其整个目录复制到其他地方——最好是在其他物理存储上(因为存储库下的 H/W 存储可能会失败)。 完成后,冷静下来寻求帮助。请不要随便乱尝试,比如让 reflog 过期的建议(完全是胡说八道)。

好了,回到正题。 由于您已经对该对象进行了核攻击,因此在恢复它之前您将不太可能继续进行。值得重复:Git 将其所有对象存储在一个数据库中(位于“.git”目录下),并且该数据库由所有 "things" 引用保存的历史记录共享那里。所以无论是哪个Git命令定位对象失败,你都可以确定它不在数据库中,你必须从别处获取它。

现在有两种可能:

  1. 那个对象是过去历史的一部分。

    如果是,那么您将有机会从其他地方托管的存储库副本中恢复它。

  2. 它是一些近期历史的一部分,没有被推到任何地方。

    如果是,那么您几乎不知所措,因为您刚刚使用第二个命令物理删除了对象数据库的一部分。

所以。首先要尝试的是从其他地方克隆这个存储库的副本,然后尝试 运行ning

$ git cat-file -t 7884ba2578c7535a2e3b70d410f0286bd2e0016f

如果它向您打印出该对象的类型,则一切正常,您可以通过 运行ning

继续恢复它
$ git cat-file <type> 7884ba2578c7535a2e3b70d410f0286bd2e0016f > foo

其中 <type> 是在上一步中获得的对象的类型(共有三个:blobtreecommit)。最后两个词使用 shell 重定向将输出内容放入名为 "foo".

的文件中

之后,获取该文件 "foo",将其复制到您的源存储库中,然后 运行

$ git hash-object -w foo

那里:此命令将从文件中提取内容并将其放入存储库中,从而使具有给定 SHA-1 哈希的对象在对象存储中可用。

您现在可以重新运行 git fsck --full.


不过,即使这会起作用(它应该),我仍然对你删除了一个所谓的"pack file"感到不安。打包文件通常包含大量过去的历史记录,因此您应该删除了很多东西。

为了解决这个问题,我会尝试克隆一个可用的副本,然后从您的源存储库中获取未推送的提交,然后我会开始使用这个克隆就地 的原始存储库。