Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing partial git history

Tags:

git

commit

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 ?

like image 240
Arno Avatar asked Jan 22 '23 19:01

Arno


2 Answers

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.

like image 81
Ben James Avatar answered Jan 27 '23 07:01

Ben James


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.

like image 23
Jeff Ferland Avatar answered Jan 27 '23 07:01

Jeff Ferland