Git是否从不删除任何信息?

7
我阅读了这篇文章:http://jenkins-ci.org/content/summary-report-git-repository-disruption-incident-nov-10th,它描述了一个事件,其中一个用户从仓库的旧状态意外触发了git push --force
现在当然需要一些清理工作来恢复原始状态分支。但是由于Git从不删除信息,因此我认为这个清理过程始终是可能的。
所以即使您进行了变基、强制推送(和其他可能重写历史的操作),原始提交仍然存在,只需要找到它们,对吗?
简而言之,是否有任何(破坏性)的Git操作实际上会删除数据?

3
如果你之后运行“git gc”和“git prune”,它就会被删除。或者你可以等待一段时间。http://alblue.bandlem.com/2011/11/git-tip-of-week-gc-and-pruning-this.html - ta.speot.is
1
是的,在 commit --amend(参见此处)、rebase、force push 等操作后变得不可访问的对象会在仓库的对象数据库中存留一段时间。尽管这些对象最终会被垃圾回收,但默认情况下,这个过程并不是立即执行的,这给了你一些时间来修复问题。 - jub0bs
1
同样地,只要对象可以从引用日志(reflog)访问到,它们就不会被删除。引用日志是您可以用来修复错误的安全网。 - Lucas Trzesniewski
2个回答

10

不通过任何引用可达的提交将最终被删除,包括引用日志(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>.

0

Git 最终会删除一些东西。它会自动进行垃圾回收,每 "5000 个对象" 进行一次。我不确定这是否指的是 5000 次提交,还是其他什么。虽然有撤销操作的方法,但当一个人从旧版本的 repo 强制推送时可能会很烦人。根据你是删除错误的推送还是还原,你的 git 历史记录中可能会有垃圾,但 git 最终会清理掉。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接