在压缩的公共和初始私有中拆分 git repo [英] Split git repo in a squashed public and initial private

查看:21
本文介绍了在压缩的公共和初始私有中拆分 git repo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Github 上开源一个项目.
有相当多的提交(超过 2k),我会将它们压缩为一个初始提交",以便从一个干净的代码库开始并隐藏一些历史内容.

I want to open-source a project on Github.
There is quite a lot of commits (more than 2k) that I would squash into one "Initial commit" in order to start with a clean codebase and hide some historical stuff.

问题是,是否有可能:

  • 保留一个包含所有初始提交的私有仓库(其中会有一些密钥、travis conf 等)
  • 拥有一个干净的公共代码库(所有提交都压缩为一个)
  • 在公共存储库上工作,并在需要时在私有存储库上合并",没有任何冲突?

谢谢.

推荐答案

您可以在当前的存储库中非常有效地执行此操作:

You can do this very efficiently in your current repo:

开始于:

# ...---o---H    HEAD, master

git cat-file -p master 
| sed '1,/^$/d' 
| git commit-tree HEAD^{tree} 
| xargs git branch public

得到

# ...---o---H    HEAD, master
#
#           H'   public  <-- H's exact content and commit message, no history

那么,

git merge -s ours public

# ...---o---H---I    HEAD, master   <-- gives later merges an accurate base
#              /
#           H''   public

git remote add public -t public its://u/r/l   # <-- '-t public` sets default push
git push public

你就完成了.

(添加了 -t public 安全播放,所以你必须做一些明确的事情来推送非公开历史)

(edit: added -t public safety play so you have to do something explicit to push non-public history)

这篇关于在压缩的公共和初始私有中拆分 git repo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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