Backup all branches in a git repository keeping what has been rebased and forced

随声附和 提交于 2019-12-05 02:34:34

问题


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?


回答1:


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 set gc.pruneExpire to never, and the same for gc.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 setting core.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.



来源:https://stackoverflow.com/questions/4686392/backup-all-branches-in-a-git-repository-keeping-what-has-been-rebased-and-forced

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!