Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial: Remove changeset from remote branch

Tags:

Is there a way to remove a from a remote changeset, or to remove an entire changeset? I accidentely pushed a .war file to a remote repo and I want to remove it.

like image 249
Miguel Ping Avatar asked May 25 '09 15:05

Miguel Ping


People also ask

What is mercurial changeset?

A changeset (sometimes abbreviated "cset") is an atomic collection of changes to files in a repository. It contains all recorded local modification that lead to a new revision of the repository. A changeset is identified uniquely by a changeset ID. In a single repository, you can identify it using a revision number.

How do I cancel my Mercurial repository?

Jonathan: Removing it is quite proper. We try to keep simple things simple in Mercurial: hg init creates . hg for you, and rm -r . hg will undo that.


2 Answers

Mercurial tries very hard to keep your data safe, so you can generally not change history.

That being said, there are numerous extensions for Mercurial that allows you to quite easily change history anyway. There is a page on the wiki about editing history. That page also explains the consequences.

In your specific case, you have to ask yourself if others will have already pulled your changeset? If so, then even if you remove it, it will still exist in their clones and you might be better off with accepting the mistake.

If you decide to remove it, I suggest using hg clone to get a copy without it. This is the safe way since it will always leave behind a backup. If you pushed [z] to the remote repository:

[x] --- [y] --- [z] 

and now want to remove it, then log into the server and do

hg clone -r y repo repo-without-z 

Then repo-without-z will contain all changests up till [y] — that is, [z] will have been removed:

[x] --- [y] 

You can then continue working and push a new changeset:

[x] --- [y] --- [w] 

If I had pulled the [z] changeset already and now pull [w] I will see two heads in the repository:

            [w]            / [x] --- [y] --- [z] 

This is not dangerous per se -- but people might be surprised. If I remove [z] from my clone I will end up with the same repository as you. But, as wrote above, this might be impractical if you have many users.

You can also use the MQ extension to strip the changeset away in-place. That way you wont make a new clone.

Finally, if you're certain that the push was the very last operation done on the server, then hg rollback can be used to remove the last transaction. But don't do this if you are the only one who can push to the repository, otherwise you might end up rolling back a different transaction.

If the repository is on Bitbucket, then you cannot log into the server. But Bitbucket has recently added a strip functionality to its web interface. Look for "Repository management" in the "Admin" section.

like image 81
Martin Geisler Avatar answered Jan 14 '23 16:01

Martin Geisler


Bitbucket does offer you a bundle (backup) upon stripping, and this does not count against your quota. The reason why it appears to do so, is only because we haven't invalidated the cache key specifying how much space you use.

This is a bug in our system, and will be remedied. Until then, rest assured that the changeset has been removed, and the backup is free :-)

like image 26
jespern Avatar answered Jan 14 '23 17:01

jespern