English 中文(简体)
Publishing partial git history
原标题:
  • 时间:2010-01-04 16:04:14
  •  标签:
  • 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 ?

问题回答

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 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.

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.





相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签