Is there any way to delete local commits in Mercurial?
So I keep making a silly mistake in Mercurial. Often times, I'll start work without doing an "hg pull" and an "hg update." When I try to push my changes, I get an error.
Is there any way to delete my local commits so I can avoid creating multiple heads, branches, etc? I just want to delete my local commits, merge my changes with the tip, and then re-commit. Sounds simple, right? I can't seem to find any way to easily delete local commits so I can cleanly merge with the tip.
Again, I'm only trying to delete local commits made with "hg ci". I don't want to modify files, revert, etc.
Enable the " mq " extension and type the following:
hg strip #changeset#
Where #changeset#
is the hash for the changeset you want to remove. This will remove the said changeset including changesets that descend from it.
For more information, check the Strip Extension.
If you get "unkown command 'strip'" you may need to enable it. To do so find the .hgrc
or Mercurial.ini
file and add the following to it:
[extensions]
mq =
Note that (as Juozas mentioned in his comment) having multiple heads is normal workflow in Mercurial. You should not use the strip command to battle that. Instead, you should merge your head with the incoming head, resolve any conflicts, test, and then push.
The strip
command is useful when you really want to get rid of changesets that pollute the branch. In fact, if you're in this question's situation and you want to completely remove all "draft" change sets permanently, check out the top answer, which basically suggests doing:
hg strip 'roots(outgoing())'
If you are using Hg Tortoise just activate the extension " mq " in:
Then select the bottom revision from where you want to start striping, by doing right click
on it, and selecting:
Just like this:
In this example it will erase from the 19th revision to the last one commited(22).
正如其他人都指出你应该拉动然后合并头部,但是如果你真的想在没有任何EditingHistory工具的情况下摆脱你的提交,那么你可以只hg clone -r
你的repo以获得除了那些改变之外的所有内容。