Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
605 views
in Technique[技术] by (71.8m points)

github - Split git repo in a squashed public and initial private

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...