git 致命:坏对象xxx
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11834108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
fatal: bad object xxx
提问by James A. Anderson
I tried reverting to a previous git commit with:
我尝试使用以下命令恢复到以前的 git commit:
git revert xxx
I'm now receiving this error as a response:
我现在收到此错误作为响应:
fatal: bad object xxx
What am I doing wrong? How do I fix this?
我究竟做错了什么?我该如何解决?
采纳答案by torek
[Edit 1, 19 Nov 2016] While this would sometimes indicate repository corruption, it turns out to occur on Windows when some command—usually, another Git in another task—is holding internal files open and locked. In this case, terminating the other task should fix it. Original answer is below.
[编辑 1, 2016 年 11 月 19 日] 虽然这有时表明存储库损坏,但事实证明,当某些命令(通常是另一个任务中的另一个 Git)打开和锁定内部文件时,它会在 Windows 上发生。在这种情况下,终止其他任务应该可以修复它。原答案如下。
[Edit 2, 6 May 2020] Suppose xxx
above resembles, e.g., b34789c0b0d3b137f0bb516b417bd8d75e0cb305
(a raw hash ID). If you got this from cut-and-paste, be sure that it's for thisrepository (it's easy to grab a hash ID from some other repository without realizing it, especially if you have multiple windows open). If you retyped it yourself, be sure there aren't any typos. If this involves submodules, make sure the submodule is up to date. See the comments on the question and some of the answers, including this one.
[ 2020 年 5 月 6 日编辑 2] 假设xxx
上面类似于,例如b34789c0b0d3b137f0bb516b417bd8d75e0cb305
(原始哈希 ID)。如果你是从剪切和粘贴中得到的,请确保它是用于这个存储库的(很容易从其他存储库中获取哈希 ID 而没有意识到它,特别是如果你打开了多个窗口)。如果您自己重新输入,请确保没有任何错别字。如果这涉及子模块,请确保子模块是最新的。查看对问题的评论和一些答案,包括这个。
bad object
with some hexadecimal number tends to mean that a tag has an invalid reference number in it, but can also occur for a few other strange cases. For instance, if I do a:
bad object
带有一些十六进制数往往意味着标签中有一个无效的参考号,但也可能发生在其他一些奇怪的情况下。例如,如果我执行以下操作:
$ git tag foo
$ vi .git/refs/tags/foo
and change the last character (in this case from 6 to 5) and write that out:
并将最后一个字符(在本例中从 6 更改为 5)并将其写出:
$ git log foo
fatal: bad object foo
What exactly is the xxx
here and where did it come from?
这里究竟是什么xxx
,它来自哪里?
回答by Prabowo Murti
I don't know the exact reason why that happens. For me, it's because I forget to pull the entire repository to my local. I have 2 or more path, and each path pulls from different branch
我不知道发生这种情况的确切原因。对我来说,这是因为我忘记将整个存储库拉到我的本地。我有 2 条或更多条路径,每条路径都来自不同的分支
/path/branch_a/ -> pulled from branch A
/path/branch_b/ -> pulled from branch B
on branch A, I made a few modification, and commit as usual. I want that commit (for example the commit ID is abcdef123
) appears on branch B, so I use
在分支 A 上,我做了一些修改,然后像往常一样提交。我希望提交(例如提交 ID 是abcdef123
)出现在分支 B 上,所以我使用
$ cd /path/branch_b/
$ git branch
master
branch_a
* branch_b
$ git cherry-pick abcdef123
This gives me that kind of error. So I need to pull the entire repository before getting that commit
这给了我那种错误。所以我需要在获得提交之前拉出整个存储库
$ git pull
remote: Counting objects: 257, done.
remote: Compressing objects: 100% (58/58), done.
remote: Total 216 (delta 187), reused 186 (delta 158)
Receiving objects: 100% (216/216), 53.13 KiB | 43 KiB/s, done.
Resolving deltas: 100% (187/187), completed with 38 local objects.
From github.com:username/my_repo
abcdef3..80c0d68 branch_a -> origin/branch_a
Already up-to-date.
$ git cherry-pick abcdef123
[branch_b ccddeef] Some commit message
1 file changed, 1 insertion(+), 1 deletion(-)
回答by PrzeoR
In my case I was cherry-picking from another branch which I didn't pull, but I tried to copy commit's IDs from GH (I haven't got this on my local where I was cherry-picking).
在我的情况下,我是从另一个我没有拉的分支中挑选的,但我试图从 GH 复制提交的 ID(我在我挑选樱桃的本地没有得到这个)。
Hope it helps ;-D
希望它有帮助;-D
回答by jorfus
I just ran into the same error (bad object [hash]) while attempting to merge from a branch my client didn't know about. (Similar to PrzeoR's case, but instead of needing a pull I needed to fetch)
我在尝试从我的客户不知道的分支合并时遇到了同样的错误(坏对象 [hash])。(类似于 PrzeoR 的情况,但我不需要拉动,而是需要获取)
In my case I needed to run git fetch to re-sync my client to the state of the server. Posting this here in case anyone reaches this thread the same way I did and could benefit from this insight.
在我的情况下,我需要运行 git fetch 将我的客户端重新同步到服务器的状态。在这里发布此信息,以防有人以与我相同的方式访问此线程,并且可以从这种见解中受益。
git pull
git cherry-pick [hash]
fatal: bad object [hash]
git fetch
remote: Counting objects: 8, done. (etc.)
From github.com:repo/branch
* [new branch] branchname
git cherry-pick [hash]
[success]
回答by unknownerror
git pull
拉
OR
或者
git fetch origin
git 获取来源
Reason: If the commit id which you are trying to cherry pick is not available in your local git, then there is a possible of this error.
原因:如果您尝试挑选的提交 ID 在您的本地 git 中不可用,则可能会出现此错误。
Doing a git pull
will fix this. If this hasn't been fixed, ask the person who has shared the commit id to push the change to origin
and do a git pull
做一个git pull
会解决这个问题。如果这还没有修复,请共享提交 ID 的人将更改推送到origin
并执行git pull
回答by Sharan
git fetch --all
git fetch --all
The git fetch command downloads commits, files, and refs from a remote repository into your local repository.
git fetch 命令将提交、文件和引用从远程存储库下载到本地存储库。
回答by quinao
I got this error while trying to cherry-pick a commit whose hash I had copied from GitHub. This commit was on a branch that I hadn't pulled, just like PrzeoR.
我在尝试挑选一个我从 GitHub 复制其哈希值的提交时遇到了这个错误。这个提交是在一个我没有拉的分支上,就像 PrzeoR。
Unlike PrzeoR a git fetch
didn't help at first because the branch had been deleted on GitHub.
Fortunately I was able to find the corresponding (closed) Pull Request and to restore the branch on GitHub.
与 PrzeoR 不同,agit fetch
起初没有帮助,因为该分支已在 GitHub 上被删除。幸运的是,我能够找到相应的(关闭的)Pull Request 并在 GitHub 上恢复分支。
回答by Matth C
I ran into the same error when trying to cherry-pick (on A) the commit of another branch ( B). Issue was stupid, simply forgot to git push the commit (B).
我在尝试挑选(在 A 上)另一个分支( B )的提交时遇到了同样的错误。问题很愚蠢,只是忘记了 git push 提交(B)。
回答by patrick
you need to do git fetch to get the latest commits in sync with local
您需要执行 git fetch 以获取与本地同步的最新提交
git fetch
混帐
then do
然后做
git revert
git恢复
回答by cycollins
The reason I ran into it was simple. I was switching back and forth between the main repository and a submodule. I tried to do a diff between one hash (in the main repository) and another that I copied from SourceTree, thinking it was an easy to get the old HEAD (I had regressed one revision to track down a regression). The old HEAD hash I grabbed was that of a submodule, and git diff
was put out with me for feeding it garbage. That's how I ended up here, and that's when I realized it was operator error. If your hash is from a different repository git will scold you with this message. However, if you do feed it garbage, would it not be better to report "XXX not a revision in this repository"? It is every bit as general an error message as "bad object" and quite a bit less likely to send someone to stack overflow for answers. I wonder if the folks in the git community would accept that pull request...
我遇到它的原因很简单。我在主存储库和子模块之间来回切换。我试图在一个哈希(在主存储库中)和另一个我从 SourceTree 复制的哈希之间做一个差异,认为获得旧的 HEAD 很容易(我已经回归了一个修订以追踪回归)。我抓取的旧 HEAD 哈希是子模块的哈希,并且git diff
和我一起出去喂它垃圾。我就是这样结束的,那时我意识到这是操作员错误。如果您的哈希来自不同的存储库,git 会用此消息骂您。但是,如果你确实喂它垃圾,报告“XXX不是这个存储库中的修订版”不是更好吗?它与“坏对象”一样普遍的错误消息,并且不太可能将某人发送到堆栈溢出以获取答案。我想知道 git 社区中的人们是否会接受那个拉取请求......