具有不同提交历史记录的公共/私有git仓库 [英] Public/Private git repos with different commit history

查看:52
本文介绍了具有不同提交历史记录的公共/私有git仓库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用类似于此处描述的公共/私有混合工作流在GitHub上管理一个开源项目: https://stackoverflow.com/a/30352360/204023

I'm attempting to manage an open source project on GitHub with a hybrid public/private workflow similar to the one described here: https://stackoverflow.com/a/30352360/204023

本质上,这描述了一个过程,其中有两个相互镜像的存储库,而没有GitHub的 fork 关系.这允许您使用标准的git远程存储库在分支之间推送/拉取更改,以及公共GitHub拉取请求以将私有更改合并到master分支中.正是我要完成的任务.

Essentially this describes a process where there are two repositories which mirror each other, without GitHub's fork relationship. This allows you to use standard git remote repositories to push/pull changes between branches, and public GitHub pull requests to merge private changes into the master branch. Exactly what I'm trying to accomplish.

我还有一个额外的要求,我想在保留敏感提交历史的同时截断PUBLIC提交历史,以防它包含敏感数据.

I have one extra requirement where I would like to truncate the PUBLIC commit history in case it contains sensitive data, while maintaining the PRIVATE commit history.

使用-depth 1 初始化新项目被证明是非法的,您不能使用浅表克隆来初始化新的仓库:![远程拒绝]主->主机(不允许进行浅更新)

Initialize the new project with --depth 1 turns out to be illegal, you can't initialize a new repo with a shallow clone: ! [remote rejected] master -> master (shallow update not allowed)

我发现的用于删除提交历史记录的解决方案涉及创建一个全新的存储库,但是有了新的回购副本,我将无法再在公共/私有副本之间进行推/拉.

The solutions I've found for truncating the commit history involve creating a brand new repository, but with a new copy of the repo I can no longer push/pull between public/private copies.

推荐答案

Git存储库中的历史记录是.提交包含文件和链接:每个提交都具有所有文件的完整快照以及其父级的哈希ID.每个分支名称都存储 latest 提交的哈希ID(单数),Git通过从末尾开始并向后工作(一次是一个父代)来查找历史记录.

The history in a Git repository is the commits. The commits contain both the files, and the linkage: each commit has a complete snapshot of all files, plus the hash ID(s) of its parent(s). Each branch name stores the hash ID (singular) of the latest commit, and Git finds the history by starting from the end and working backwards, one parent at a time.

由于每个提交的哈希ID是该提交的内容的加密校验和(包括父哈希),因此 last 提交的哈希ID取决于历史记录中的每个提交的哈希ID,这些历史记录是通过从该提交向后走到其他所有可到达的提交而形成的.(从技术角度讲,这是 Merkle树 的一种形式.)

Since the hash ID of each commit is a cryptographic checksum of the contents of that commit—including the parent hash—the hash ID of the last commit depends on the hash IDs of every commit in the history formed by walking backwards from that commit through every other reachable commit. (In technical terms this is a form of Merkle tree.)

所有这些的含义是,可以将存储库DAG的较短的版本保持公开状态,而将较长的版本(较短的提交内容和添加的提交内容)保持为公开状态.私有的,但是 不可能有一个公开的版本,它忽略了一些历史性的提交而保留了其他历史性的提交.或者,您也可以使用平行图,即独立的DAG:一个包含公共历史记录,另一个包含私有历史记录.如果通过Git子模块执行此操作,则可以合理地确定不会释放私有信息,但这确实构成了强大的结构约束:公共内容必须全部为子目录.

The implication of all of this is that it's possible to keep a shorter version of the repository DAG public, and a longer version (shorter plus added commits) as the private one, but it's not possible to have a public version that omits some historical commits while keeping others. You can also, or instead, use parallel graphs, i.e., independent DAGs: one that contains the public history, and one that contains the private history. If you do this through Git submodules, you can be reasonably sure of not releasing the private information, but that does impose a strong structural constraint: the public stuff must all be a subdirectory.

这篇关于具有不同提交历史记录的公共/私有git仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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