使用git,我如何创建存储库的几乎没有历史记录的克隆 [英] Using git, how can I create a mostly history-less clone of a repository

查看:328
本文介绍了使用git,我如何创建存储库的几乎没有历史记录的克隆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已有2年历史的存储库,从本质上来说它是一个私有存储库,因此它在历史记录中的各个阶段都存在:密钥文件,加密密钥,不同位置的大量映像等等,等等.存储库,所有存储库都不再被跟踪,但仍存在于历史记录中.

由于我们要招募新的开发人员,因此该资源现在正在共享,我希望从一个基本干净的存储库开始一个全新的开始.但是,在这个过渡时期,我可能还必须处理旧的存储库,在两个存储库之间共享补丁/提交.

打破git中以前的历史记录并保持向后兼容性尽可能清晰地共享旧存储库和新的干净存储库之间的提交功能的最佳方法是什么?/p>

目标:

  1. 以历史记录中无法使用的方式进行敏感提交 新的存储库.
  2. 允许新存储库中的全部功能(克隆,推送,提取以及git的所有正常功能)
  3. 最大限度地提高旧存储库识别来自新存储库的补丁/提交的能力
  4. [不太重要],因为在工作副本中不存在的古代提交中没有二进制文件,因此使新的repo更快.

解决方案

仅在现有存储库中创建一个清晰的新分支将无济于事:如果用户可以阅读此分支,则他们也可以访问您的旧分支包含您的敏感信息的分支.为了克服这个问题,您将不得不创建一个没有(或仅有有限)关于过去的知识的新仓库.

为此,我将执行以下操作:

  • 采用相对较新的回购状态(例如最后标记的版本或类似的内容,例如V1.0),以此作为开始创建 new 回购( c1>),供您的新开发人员使用.

  • 然后,在您的计算机上,添加一个名为远程 c2>指向保存旧敏感数据的旧存储库.

  • 接下来,从V1.0进行所有提交,直到从oldrepo进行最新提交,并且克隆来自newrepo的裸仓库( newrepo.git).您所有的开发人员都会克隆newrepo.git并对其进行处理.

如果要将补丁等从newrepo.git导入到oldrepo中,反之亦然,则此操作将由完成,即您的同事将由format-patch生成的所需补丁发送给您然后您将它们am放入旧存储库中.如果您在oldrepo中做了一些修复,则可以再次将它们cherry-pick放入newrepo.git中,并使开发人员可以使用它们.

这限制了您访问oldrepo的权限,您的同事将永远不会看到任何敏感数据.

I have a 2 year old repository that started off as essentially a private repository, so it contained in it's history at different points: key files, encryption keys, large sets of images in various places, etc etc, in the history of the repository, all of which are no longer tracked but still exist in the history.

The source is now becoming shared, since we're bringing on new developers, and I want to make a clean start with a mostly clean repository. However, during this transitional period, I may have to deal with the old repository as well, sharing patches/commits between the two repositories.

What is the best way to break away from the previous history in git and yet retain backwards compatibility the ability to share commits between the old repository and the new clean repository, as cleanly as possible?

Objectives:

  1. Make sensitive commits in the way past of the history unavailable in the new repository.
  2. Allow full functionality in the new repository (clone, push, fetch, everything that's normal for git)
  3. Maximize the ability for the old repo to recognize patches/commits that come from the new repo
  4. [Less important] Make new repo faster due to not having binaries in ancient commits that aren't present in working copy.

解决方案

Just creating a new, clear branch in your existing repo won't help: If the users could read this branch, they'll also have access to your old branches that contain your sensitive information. To overcome this, you'll have to create a new repo with no (or only limited) knowledge about the past.

To achieve this, I'd do the following:

  • Take a relatively new state of your repo (e.g. the last labeled version or something like that, say V1.0) and use this as a start to create a new repo (newrepo) that is used by your new developers.

  • Then, on your machine, add a remote called oldrepo that points to the old repository holding the old sensitive data.

  • Next, take all commits from V1.0 until latest from oldrepo and cherry-pick them into your new repo. At this point, your new repo has the same state as oldrepo without the dirty history.

  • Now, clone a bare repo from newrepo (newrepo.git). All your developers clone newrepo.git and work on it.

If it comes to take patches etc. from newrepo.git into oldrepo or vice versa, this operation will be done by you, i.e. your colleagues send you needed patches generated by format-patch and you am them into the old repo. If you have some fixes done in oldrepo, you could again cherry-pick them into newrepo.git and make them available to your devs.

This limits the access to oldrepo to you and your colleagues will never see any sensitive data.

这篇关于使用git,我如何创建存储库的几乎没有历史记录的克隆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆