简体   繁体   English

你可以在GitHub上恢复/恢复已删除的分支多长时间?

[英]For how long can you restore/recover a deleted branch on GitHub?

This is not a question on how to restore lost branches in Github, but rather how long you have to restore a deleted branch through the following user case story: 这不是关于如何在Github中恢复丢失分支的问题,而是通过以下用户案例故事恢复已删除分支的时间:

Within a pull request (often used as a place for code review) the branch can be merged and then deleted, all in the github GUI. 在拉取请求(通常用作代码审查的地方)内,可以在github GUI中合并然后删除分支。 Should you choose to delete it, you are given the option with a bold and underlined word, to "restore" the branch. 如果您选择删除它,您将获得带有加粗和带下划线的单词的选项,以“恢复”分支。

I suspect this option has a time limit and that github doesn't keep this available indefinitely. 我怀疑这个选项有一个时间限制,并且github无法无限期地保留它。

Does github have a time limit on how long you can do this? github有多长时间可以做到这一点吗? If it does, what is that time limit? 如果是的话,那个时间限制是多少?

I asked GitHub Support , this was their response (emphasis mine): 我问GitHub支持 ,这是他们的回应(强调我的):

We use a separate ref namespace for all Pull Requests which we use for various things including restoring the branch. 我们为所有Pull请求使用单独的ref命名空间,我们将其用于各种事情,包括恢复分支。 Since we keep those [Pull Request] refs indefinitely, there's no time limit on restoring a branch . 由于我们无限期地保留那些[Pull Request] refs, 因此恢复分支没有时间限制

You can see these special references in your remote by using the following: 您可以使用以下命令在遥控器中查看这些特殊参考:

$ git ls-remote | grep pull
From git@github.com:<username>/<remote>.git
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa        refs/pull/1/head
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        refs/pull/1/merge
cccccccccccccccccccccccccccccccccccccccc        refs/pull/2/head
dddddddddddddddddddddddddddddddddddddddd        refs/pull/2/merge

The references are namespaced under refs/pull/<pull request number>/ . 引用在refs/pull/<pull request number>/下命名。 The head reference points at the tip of the branch that's being pull requested, ie the last commit on the branch. head引用指向被拉请求的分支的尖端,即分支上的最后一次提交。 I'm not sure what the merge reference is though. 我不确定merge引用是什么。

GitHub support would have a definitive answer, but I suspect it is based on the default 90 days period before automatic purge of the reflog . GitHub支持将有一个确定的答案,但我怀疑它是基于自动清除reflog之前的默认90天期限。

gc.<pattern>.reflogexpire

git reflog expire removes reflog entries older than this time; git reflog expire删除比此时更早的reflog条目; defaults to 90 days . 默认为90天
With " <pattern> " (eg " refs/stash ") in the middle the setting applies only to the refs that match the <pattern> . 在中间使用“ <pattern> ”(例如“ refs/stash ”),该设置仅适用于与<pattern>匹配的引用。

But... I you had a local copy with that branch still declared in it... nothing would prevent you to push said branch back to the gitHub repo ;) 但是......我有一个本地副本,该分支仍然在其中声明...没有什么会阻止你将所述分支推回到gitHub仓库;)

Cupcake 's answer (upvoted) give that support answer: no limit , which means those two settings are both set to never : Cupcake答案 (upvoted)给出了支持答案: 没有限制 ,这意味着这两个设置都设置为never

  • gc.reflogexpire
  • gc.reflogexpireunreachable

That makes sense for a hosting repo service which doesn't modify those repos locally, and only store modifications pushed from external contributors. 这对于托管回购服务是有意义的,该服务不会在本地修改这些回购,并且只存储从外部贡献者推送的修改。


Update Git 2.22 (Q2 2019, five years later): that last case (setting gc.reflogexpire and gc.reflogexpireunreachable to never ) is better handled. 更新Git 2.22(2019年第二季度,五年后):最后一种情况(将gc.reflogexpiregc.reflogexpireunreachable设置为never )可以更好地处理。

See commit bf3d70f , commit 978f430 (28 Mar 2019), commit fe66776 , commit a65bf78 , commit cd8eb3a , commit e5cdbd5 (15 Mar 2019), and commit 8bf1444 (13 Mar 2019) by Ævar Arnfjörð Bjarmason ( avar ) . 请参阅提交bf3d70f提交978f430 (2019年3月28日), 提交fe66776提交a65bf78提交cd8eb3a提交e5cdbd5 (2019年3月15日),并提交8bf1444 (2019年3月13日),由ÆvarArnfjörðBjarmason( avaravar
(Merged by Junio C Hamano -- gitster -- in commit f3c19f8 , 25 Apr 2019) (由Junio C gitster合并- gitster -提交f3c19f8 ,2019年4月25日)

gc : handle & check gc.reflogExpire config gc :handle&check gc.reflogExpire config

Don't redundantly run " git reflog expire --all " when gc.reflogExpire and gc.reflogExpireUnreachable are set to " never ", and die immediately if those configuration valuer are bad. gc.reflogExpiregc.reflogExpireUnreachable设置为“ never ”时,不要冗余地运行“ git reflog expire --all ”,如果那些配置gc.reflogExpire gc.reflogExpireUnreachable则立即死掉。

As an earlier "assert lack of early exit" change to the tests for " git reflog expire " shows, an early check of gc.reflogExpire{Unreachable,} isn't wanted in general for " git reflog expire ", but it makes sense for " gc " because: 作为早期的“断言缺乏提前退出”改变为“ git reflog expire ”的测试显示, gc.reflogExpire{Unreachable,}的早期检查通常不需要“ git reflog expire ”,但它有意义为“ gc ”因为:

  1. Similarly to 8ab5aa4 (" parseopt : handle malformed --expire arguments more nicely", 2018-04-21, Git v2.18.0-rc0) we'll now die early if the config variables are set to invalid values. 8ab5aa4 (“ parseopt :处理格式--expire更好地--expire参数”,2018-04-21,Git v2.18.0-rc0)类似,如果将配置变量设置为无效值,我们现在会提前死亡。
    We run " pack-refs " before " reflog expire ", which can take a while, only to then die on an invalid gc.reflogExpire{Unreachable,} configuration. 我们在“ reflog expire ”之前运行“ pack-refs ”,这可能需要一段时间,然后才会死于无效的gc.reflogExpire{Unreachable,}配置。

  2. Not invoking the command at all means it won't show up in track output, which makes what's going on more obvious when the two are set to " never ". 根本不调用命令它不会显示在轨道输出中,这使得当两者设置为“ never ”时,情况会更明显。

  3. As a later change documents we lock the refs when looping over the refs to expire, even in cases where we end up doing nothing due to this config. 作为后来的更改文档,我们在循环refs到期时锁定引用,即使在我们最终由于此配置而无法执行任何操作的情况下也是如此。

Note that some pull-request pages on GitHub will not show the Delete/Restore branch buttons, even though the references are safely stored as described by Cupcake . 请注意,GitHub上的某些拉取请求页面不会显示 “删除/恢复”分支按钮,即使引用是按照Cupcake的描述安全存储的。

This probably means the same branch was used again in a later pull request. 这可能意味着在稍后的拉取请求中再次使用相同的分支。 Search the repo (in GitHub) for the branch name and check the latest pull request on that branch. 在repo(在GitHub中)中搜索分支名称并检查该分支上的最新pull请求。 You should find the UI to restore (or delete) the branch there. 您应该找到用于恢复(或删除)分支的UI。

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

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