在一个压扁的公共和私人初始分割git回购 [英] Split git repo in a squashed public and initial private

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

问题描述

我想在Github上开源项目。

为了开始一个清理工作,我需要将很多提交(超过2k)压缩到一个初始提交中代码库和隐藏一些历史的东西。



问题是,是否有可能:


  • 使用所有初始提交

  • 保留一个私有的repo(其中将有一些秘密密钥,travis conf,...)具有干净的公共代码库(所有提交都被压缩为一个)

  • 并且在私人需要时处理公共回购和合并而不会发生任何冲突?


    谢谢。

    解决方案

    您可以在当前的回购中非常高效地执行此操作:


    $ b

    从以下开始:

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

    do

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

    得到

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

    #H'public < - H确切的内容和提交消息,无历史记录

    然后,

      git merge -s our public 

    #...--- o --- H --- I HEAD,master< - 稍后将合并一个精确的基
    #/
    #H''public

    git remote add public -t public its:// u / r / l#< - '-t public`设置默认推送
    git push public

    完成了。



    (编辑:添加 -t public 安全播放,所以你必须做一些明确的操作来推送非公开的历史记录)

    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.

    The question is, is it possible to:

    • keep a private repo (on which there will be some secret keys, travis conf, ...) with all initial commits
    • have a clean public codebase (all commits squashed into one)
    • and work on the public repo and "merge" when needed on the private without any kind of conflicts ?

    Thanks.

    解决方案

    You can do this very efficiently in your current repo:

    Starting from:

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

    do

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

    to get

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

    Then,

    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
    

    and you're done.

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

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

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