tags:

views:

60

answers:

3

I would like to publish my git history to a public repository but would like to remove older commits. All the ways I have seen to do this alter the newer commit's SHA1s, which is not an option since I want to be able to push to the modified repo. Is there anyway to do this ?

+1  A: 

If you modify history then you will inevitably alter the SHA1 hashes of the newer commits. This is because the hashes are based on the entire history, not just the latest snapshot. This is by design, to catch corruption (accidental or malicious) of any part of the repository.

Ben James
+1  A: 

I'm surely missing something, but can't you use something like:

git log --since="2009-1-1" -p

To extract only the commits after a certain date or:

git log -p 18f822e..HEAD

to get all the history after a specific commit.

filippo
+1  A: 

Ben James' comment is accurate. However, what you can do is start a new branch in your current repository. From there, build that branch's history up as you wish. When you publish, only push that particular public branch out. This will get you the functionality you're looking for.

Here's how I just did it in my test case:

git branch stackoverflow #Get myself a working branch from current
git rebase -i deadbeef   #0xDEADBEEF is the hex of my first commit

Squash everything you want hidden. Note that git gets PISSED if you have a repository that has more than one root. This shouldn't be possible, but I just discovered that via some magical svn conversions, I created such a beast.

A project can also have multiple roots, though that isn't common (or necessarily a good idea).

Export the new branch. From there, you can treat that as the master development branch and everything else as a topical or historical branch that doesn't get exposed.

Autocracy