备份 git 存储库中的所有分支,保留已重新定位和强制的内容
我正在寻找一种解决方案来备份多个共享 git 存储库,每个存储库都有多个分支,并且某些分支会被重新定位并强制(我知道这违反了最佳实践,但这是我现在必须处理的事情)
我在想一个简单的 git clone --mirror ,然后定期 git 远程更新 就足够了,但这不会保留任何通过推力重新建立基础的东西。
我尝试了 git bundle ,但我认为这对于我在这里尝试做的事情来说不是一个好的解决方案。
寻找增量、轻量且易于用于恢复的东西,我想也许可以使用 git format-patch 来编写脚本记录任何地方发生的每个新提交。这对于任务来说是否太过分了?
I am looking for a solution to backup multiple shared git repositories, each with multiple branches, and some of the branches get rebased and forced (I know that's against best practices, but it is something that I have to deal with now)
I was thinking a simple git clone --mirror
and then periodically git remote update
would be enough, but that won't keep anything that gets rebased with a push force.
I experimented with git bundle
and I don't think it's a good solution for what I am trying to do here.
Looking for something incremental, light and easy to use for recovery, I am thinking maybe git format-patch
can be used to script the recording of every single new commit that happens anywhere. Is this too much for the task?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为克隆 --mirror 方法值得回顾。如果您想恢复被强制推送的分支的过去位置,只需查看 reflogs 即可。为了绝对确定这一点,您可以将
gc.pruneExpire
设置为never
,并且将gc.reflogExpireUnreachable
设置为gc.reflogExpireUnreachable
,以便 reflogs 和 unreachable对象永远不会被删除。这应该涵盖你。重要提示:默认情况下,裸存储库中的引用日志是禁用的。您可以通过设置 core.logAllRefUpdates 来启用它们。请注意,推送到的存储库中的引用日志将包含发生的任何强制推送的记录。如果您想更加确定这一点,您甚至可以编写一个更新挂钩来检测传入的强制更新并将它们记录在特殊的地方,也许可以通过创建一个引用,例如
refs/backups/mybranch-{n}< /代码>。
事实上,一些分支经常被重新设置基础并没有什么问题,只要它是以一种明确定义的方式进行的,这样就不会让人措手不及。 git.git 中的 pu 分支就是一个完美的例子。
I think the
clone --mirror
approach is worth looking back at. If you want to recover a past position of a branch which was force-pushed, just have a look at the reflogs. To be absolutely sure about this, you can setgc.pruneExpire
tonever
, and the same forgc.reflogExpireUnreachable
, so that reflogs and unreachable objects will never be removed. That ought to cover you. Important note: reflogs are by default disabled in bare repositories. You can enable them by settingcore.logAllRefUpdates
.Do note that the reflogs in the pushed-to repository will contain records of any forced pushes that happen. If you want to be even more sure about this, you could even write an update hook that detects incoming forced updates and records them somewhere special, perhaps by creating a ref, something like
refs/backups/mybranch-{n}
.And really, there's nothing wrong with some branches being rebased frequently, as long as it's in a well-defined way, so that no one is caught off guard. The
pu
branch in git.git is a perfect example of this.