【问题标题】:Does Git never delete any information?Git永远不会删除任何信息吗?
【发布时间】:2014-12-14 10:43:08
【问题描述】:

我读过这篇文章: http://jenkins-ci.org/content/summary-report-git-repository-disruption-incident-nov-10th

描述了用户意外从存储库的过时状态触发git push --force 的事件。

当然,这需要进行一些清理以恢复原始状态分支。但由于 Git 从不删除信息,据我所知,此清理过程始终是可能的。

因此,即使您 rebase、push --force(和其他可能重写历史的操作)原始提交仍然存在,它们只需要被发现对吗?

简而言之,git 中的任何(破坏性)操作实际上会删除数据吗?

【问题讨论】:

  • 好吧,如果你 gc+prune 之后它就会消失。或者只是等待。 alblue.bandlem.com/2011/11/…
  • 是的,在commit --amend(参见this)、rebase、强制推送等操作之后变得无法访问的对象会在 repo 的对象数据库中存活一段时间。尽管这些对象最终会被垃圾回收,但默认情况下,此过程不会立即进行,并给您一些时间来修复混乱。
  • 此外,只要对象可以从 reflog 中访问,它们就不会被删除。 reflog 是您的安全网,您可以使用它来修复错误。

标签: git garbage-collection object-oriented-database


【解决方案1】:

无法通过任何引用访问的提交将最终被删除,其中包括 reflog。发生这种情况的默认时间段非常保守。您可以通过git config 使用几个选项来调整此设置,请参阅下面的一些特定选项。

很多人(包括我自己)会建议您设置接收挂钩以拒绝非快进合并,这在很大程度上会使这个问题变得没有意义(在服务器上,个人仍然可能会丢失未推送的本地工作)。

gc.auto
When there are approximately more than this many loose objects in the repository, git gc --auto will pack them. Some Porcelain commands use this command to perform a light-weight garbage collection from time to time. The default value is 6700. Setting this to 0 disables it.
gc.pruneexpire
When git gc is run, it will call prune --expire 2.weeks.ago. Override the grace period with this config variable. The value "now" may be used to disable this grace period and always prune unreachable objects immediately.

gc.reflogexpire
gc.<pattern>.reflogexpire
git reflog expire removes reflog entries older than this time; defaults to 90 days. With "<pattern>" (e.g. "refs/stash") in the middle the setting applies only to the refs that match the <pattern>.

gc.reflogexpireunreachable
gc.<ref>.reflogexpireunreachable
git reflog expire removes reflog entries older than this time and are not reachable from the current tip; defaults to 30 days. With "<pattern>" (e.g. "refs/stash") in the middle, the setting applies only to the refs that match the <pattern>.

【讨论】:

    【解决方案2】:

    Git 最终会删除一些东西。它自动垃圾收集每“5000 个对象”。我不确定这是否意味着 5000 次提交,或者它是否指的是其他东西。有一些方法可以撤消事情,尽管当一个人从旧版本的回购中强制推送时可能会很烦人。根据您是删除错误推送还是还原,您的 git 历史记录中会有垃圾,但 git 最终会清理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-10
      • 2017-09-10
      • 2016-12-29
      • 2022-10-06
      • 2014-03-11
      • 1970-01-01
      • 1970-01-01
      • 2016-08-26
      相关资源
      最近更新 更多