Is there a way to hide commits from certain users? I want to make a private repo public but don’t want people to see all of my old commits. Some of them have passwords and API keys. Others are just plain irrelevant to what I want to provide.
The private repo is currently hosted on GitHub. I want to flip the switch and make it Public and Open Source, but that would reveal the old commits I don’t want people to see.
I know that one way I could go about this is to create an entirely new repository, but I’ve reached the repo limit for my account. Looking for the fastest and easiest way to solve the problem. Open to whatever approach works — including creating a new repo, if that happens to be the best way.
If you do indeed “hide” those commits, then you’re effectively creating a new repo. A commit’s SHA1 depends on all of its content, and upon its parents, so changing a single commit changes everything afterward.
If the scope of things to hide is enormous, you may be best off not exporting any history. But hopefully things are fairly isolated, and you can solve your problems with
git filter-branch. The manpage describes its capabilities pretty well, including a few toy examples (for example how to remove files from history), and there are a lot more examples online, including here. You might end up making multiple passes, e.g. one to remove certain files, and one to remove certain types of commits.The key things that might be useful to you:
--index-filterwill let you remove or rename a given set of files or directories – it only lets you modify the index, without checking out the files, so it’s fast;--env-filterwill let you very rapidly rewrite author/committer information; and--tree-filter, the last resort, will actually check out the entire tree at each step, and let you modify files in-place (e.g. search and replace to remove passwords)filter-branch completely rewrites all history on any refs you specify, and leaves the original refs in refs/originals in case you need them. For a variety of reasons, not the least of which is safety, it’s best to use it in a fresh clone.