简体   繁体   English

Git:删除损坏的存储

[英]Git: Remove broken stash

I've got a broken stash:我有一个破损的藏匿处:

% git stash drop            
fatal: log for refs/stash is empty
% cat .git/logs/refs/stash
%

It does show up in git log --all , though:不过,它确实出现在git log --all

% lal

*   f32cdce - (HEAD -> develop, origin/develop) (44 minutes ago) <Williams, Ken>
|\  
| * 05cc7d3 - (3 weeks ago) <Ken Williams>
| * 6d9c8ae - (3 weeks ago) <Ken Williams>
| | * 3fb311d - (refs/stash) (3 weeks ago) <Ken Williams>
| |/| 
| | * 19be16e - (3 weeks ago) <Ken Williams>
| |/  
| * ffea5e2 - (i2) (9 weeks ago) <Ken Williams>

( lal is my alias for git log --graph --pretty=format:'%h -%C(yellow)%d%Creset %Cgreen(%ad) %C(bold blue)<%an>%Creset' --all .) ( lal是我的别名git log --graph --pretty=format:'%h -%C(yellow)%d%Creset %Cgreen(%ad) %C(bold blue)<%an>%Creset' --all 。)

I did a git stash apply 3fb311d , so I've got the content of the stash secured.我做了一个git stash apply 3fb311d ,所以我得到了安全的 stash 内容。 Now, how can I remove that refs/stash from the tree so it doesn't keep complaining?现在,我怎样才能从树中删除refs/stash ,以便它不会一直抱怨?

EDIT编辑

Even after deleting the refs/stash reference as suggested by @mark-adelsberger, the commits show up in the history listing:即使按照@mark-adelsberger 的建议删除了refs/stash引用,提交也会显示在历史列表中:

% lal

*   f32cdce - (HEAD -> develop, origin/develop) (31 hours ago) <Williams, Ken>
|\  
| * 05cc7d3 - (3 weeks ago) <Ken Williams>
| * 6d9c8ae - (3 weeks ago) <Ken Williams>
| | * 3fb311d - (3 weeks ago) <Ken Williams>
| |/| 
| | * 19be16e - (3 weeks ago) <Ken Williams>
| |/  
| * ffea5e2 - (i2) (9 weeks ago) <Ken Williams>
| * 199af47 - (9 weeks ago) <Ken Williams>
...

This is using Git 2.29.0 (homebrew) on OS X 10.15.7.这是在 OS X 10.15.7 上使用 Git 2.29.0(自制软件)。

Update - Added notes at end based on edited question更新- 根据编辑的问题在最后添加注释


If .git/refs/stash is empty (or non-existant) yet git log shows a refs/stash , then I would suspect the stash ref got added to your packed-refs file somehow.如果.git/refs/stash为空(或不存在)但 git log 显示refs/stash ,那么我怀疑stash ref 以某种方式添加到您的packed-refs文件中。

You can confirm the existence of the ref (regardless of its representation on disk) with您可以使用以下命令确认引用的存在(无论其在磁盘上的表示如何)

git for-each-ref refs/stash

and if this shows refs/stash (as I think it will), then you can delete the ref with如果这显示refs/stash (正如我认为的那样),那么您可以删除 ref

git update-ref -d refs/stash

As a reminder this is a potentially destructive command;提醒一下,这是一个潜在的破坏性命令; in the specific case where you know you either have saved a ref to that data, or no longer want it, then it's fine.在特定情况下,您知道您已经保存了对该数据的引用,或者不再需要它,那么就可以了。


So it's not clear to me what would cause log to report a commit that doesn't seem to be reachable (based on the graph and on the lack of refnames on that particular commit).因此,我不清楚什么会导致日志报告似乎无法访问的提交(基于图表以及该特定提交缺少引用名称)。 If I had a repo in that state I think I could figure out what's going on, but I really don't know how to reproduce the symptom.如果我在那种状态下有一个回购,我想我可以弄清楚发生了什么,但我真的不知道如何重现这种症状。

My best suggestion is to do我最好的建议是做

git for-each-ref |grep 3fb311d

to see if for some reason a ref just isn't being named in the log.查看是否由于某种原因在日志中没有命名引用。 IF that shows nothing, another idea is just如果什么都没有显示,另一个想法就是

git for-each-ref

Or see if或者看看

git fsck

tells you anything useful.告诉你任何有用的东西。 If any of this turns up more information, I'll be happy to look at it and update with more suggestions.如果其中任何一个出现更多信息,我将很乐意查看它并更新更多建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM