amirouche
amirouche

Reputation: 7873

How do I permanently remove (obliterate) files from history?

I commited (not pushed) a lot of files locally (including binary files removing & adding...) and now when I try to push it takes a lot of time. Actually I messed up my local repo history.

How could I avoid this mistake in the future ? Can I transform a set of local revision 1->2->3->4 to 1->2 with 2 being the final revision of the local clone ?

edit: since I was in hurry I started a new remote repo from scratch with revision 4. In the future I will go with the marked answer as it seems easier but I will dig other solutions to see the truth. Thx for your support.

Upvotes: 5

Views: 2886

Answers (2)

milan
milan

Reputation: 12402

It's not clear from your question whether those changes got pushed. If they're still local, you can more or less get rid of them easily. convert is one option. You can also use MQ (mercurial queues). Check the EditingHistory wiki article for a detailed explanation. It recommends MQ being the simplest approach.

To prevent that kind of mistakes, you should probably add a hook to reject 'bad' commits, given that you can describe them programatically ;)

Upvotes: 2

Ry4an Brase
Ry4an Brase

Reputation: 78330

Mercurial history is immutable, you can't delete using the normal tools. You can, however, create a new repo without those files:

$ hg clone -r 1 repo-with-too-much new-repo

that takes only revisions zero and one from the old repo and puts them into a new repo. Now copy the files from revision four into the new repo and commit.

This gets rid of those interstitial changesets, but any repo you have out there in the wild still has them, so when you pull you'll get them back.

In general once you've pushed a changeset it's out there and unless you can get everyone with a clone to delete it and reclone you're out of luck.

Upvotes: 1

Related Questions