[英]Git restore branch that was deleted both locally and on the server
I am trying to restore a branch that was deleted about a week ago from the remote server.我正在尝试恢复大约一周前从远程服务器中删除的分支。 Since that time I completely blew away my local repo for that project so there is no local version of that branch either.
从那时起,我彻底销毁了该项目的本地存储库,因此也没有该分支的本地版本。 I tried "git fsck" but didn't see anything related to my branch there.
我尝试了“git fsck”,但在那里没有看到与我的分支相关的任何内容。
通过git reflog
(分支上的最后一次提交)查找 sha 并在命令行提示符下执行git checkout -b <branch> <sha>
。
One possibility would be some local repo somewhere that hasn't done a git fetch --prune
, that'd still be tracking the last-known tip.一种可能性是某处没有执行
git fetch --prune
,它仍然会跟踪最后一个已知的提示。
But failing that, since the branch was deleted on the server "about a week ago", the factory-default expiry on unreferenced objects hasn't passed so auto-gc shouldn't have cleaned it out yet.但是如果失败了,由于“大约一周前”在服务器上删除了分支,未引用对象的出厂默认到期时间尚未过去,因此 auto-gc 不应该将其清除。 ssh in to that repo, do
ssh 到那个 repo,做
git fsck --lost-found --connectivity-only
and git show
or maybe eg git log --online --graph --decorate master..$id
the id's in the lost-found/commits
directory to see if any of them look good.和
git show
或者例如git log --online --graph --decorate master..$id
在lost-found/commits
目录中的 id 以查看它们中的任何一个看起来不错。 Any that do, you can make a new branch tip for them, if the commit's still in the repo its history's still there too.任何这样做,您都可以为他们制作一个新的分支提示,如果提交仍在回购中,其历史记录也在那里。
If you don't want to operate on a live server you can just rsync or tar or whatever the repo itself, the whole thing, to wherever you want, then spelunk at leisure.如果你不想在实时服务器上操作,你可以只 rsync 或 tar 或任何 repo 本身,整个事情,到任何你想要的地方,然后在闲暇时进行探索。 You might have to remove any stray
find -name \\*.lock
files if somebody was pushing during the copy, or play with the configs if there are any hardwired paths configured going outside the repo itself but that's unusual.如果有人在复制过程中推送,您可能必须删除任何杂散的
find -name \\*.lock
文件,或者如果有任何硬连线路径配置在 repo 本身之外,则使用配置,但这是不寻常的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.