I have a local git project that I would like to open source by pushing to a public Github repo. Let say that this is the local project history:
F-G [feature-1]
/ \
A-B-C-D-E H-I-J [master]
^
\(first public ready commit)
However, I have a problem: during prototyping I've hard-coded some sensitive data in. Let's say that up to commit D there's data in the code that I would not like anyone to see.
How can I preserve the change history in my local repo but only publish from E
onwards?
I'm considering two approaches:
E
, which would make E
the initial release.master
.Command line snippets welcome!
In this case, I'd do it with a graft file and rewriting:
First, tag D and E. I'll assume they can be referred to as D and E from here on.
Now, fake E's history so that it doesn't have a parent:
git rev-parse E >.git/info/grafts
Then, rewrite the commits to reflect this history:
git filter-branch -- --all
Now, you have a local tag D that points to the sensitive data, and a local tag E that points to the clean data as the initial commit:
F'-G' [feature-1] / \ E' H'-I'-J' [master] A-B-C-D
Now, for your local needs, it may be helpful to have E' show D as the parent again, and this can be done with a graft file again:
echo `git rev-parse E` `git rev-parse D` >.git/info/grafts
Note that you don't want to run git filter-branch
now.
Locally, your history will look like this:
F'-G' [feature-1] / \ A-B-C-D-E' H'-I'-J' [master]
but if you push, you'll push the real E', which has no parent, so remotely, you'd only get
F'-G' [feature-1] / \ E' H'-I'-J' [master]