Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8190921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:47:11+00:00 2026-06-07T03:47:11+00:00

Using git, I can throw away a mistaken or accidental commit using a command

  • 0

Using git, I can throw away a mistaken or accidental commit using a command like

git reset --soft HEAD^

which resets the current branch (such as master) to the current revision’s parent commit HEAD^ without touching the working tree – you can replace --soft with --hard if you want to obliterate the working tree as well.

In addition, if I want to get rid of more than one commit, I can use a command like

git reset --hard 53b94d0

which brings me back exactly to commit 53b94d0 as if I had never committed anything after that.

What’s the Mercurial (hg) equivalent?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:47:12+00:00Added an answer on June 7, 2026 at 3:47 am

    Though Mercurial doesn’t provide an easy alternative and shies away from the idea of mutable history, there are a few ways to achieve something close. In this post, I’ll outline a few of them.

    hg rollback

    If you specifically want to undo your last commit, you can use:

    hg rollback
    

    which will undo the commit (which doesn’t touch the working tree – you should be able to follow it with a hg revert --all or hg update -C if you want to reset the entire working directory as well).

    hg clone -r

    Suppose you want to reset your repository called giraffe to revision 77182fb7451f. If you cd into the parent directory and run:

    hg clone -r 77182fb7451f giraffe new-giraffe
    cp giraffe/.hg/hgrc new-giraffe/.hg/
    

    then you’ll end up with new-giraffe, a repository at revision 77182fb7451f. (The cp is necessary to ensure that new-giraffe paths (like git’s “remotes”) correctly point to the origin repo instead of to the giraffe folder as it would by default.)

    This is faster than recloning from the internet because it only copies files locally on your disk (and on many systems, hard-links them to save even more time and space), but can still be really time-consuming if your repository is large.

    hg strip

    If you want to do more complicated things with modifying the commit history (which is somewhat frowned on in the hg world, by the way), first enable the Mercurial Queues extension by adding the following lines to your .hgrc (there’s no need to specify a path after the equals sign):

    [extensions]                                                                    
    mq =
    

    This gives you (among other useful things) the hg strip command to completely remove a changeset and all of its descendants from a repository. Thus you can use a command like:

    hg strip 1cc72d33ea76
    

    if 1cc72d33ea76 is the first “bad” changeset in your repository that you want to remove.

    Unfortunately, it’s often hard to remove exactly the right changesets using this method and it’s all too easy to end up with multiple heads (which you can view using hg heads), requiring tedious repeated application of hg strip before you can get to where you want to be with no extra heads.

    hg strip using revsets

    Using hg revsets you can delete all the ancestors of . (the current revision) which are not ancestors of the revision you want to revert to, using a command like:

    hg strip "ancestors(.) and not ancestors(77182fb7451f)"
    

    Make sure to first run:

    hg log -r "ancestors(.) and not ancestors(77182fb7451f)"
    

    which will show you all the changesets that hg strip would remove, so you can make sure you don’t irreparably harm your commit history (because you have backups… right?).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Git, how can you find the difference between the current and the last
Using git , if I make git branch --all I can see all remotes
I'm using git gui and I can't see my branch. I know I checked
I know you can track a svn repo with git by using git svn
Can I preview the changes that will be checked-in to TFS without using git
I am setting up a Git repository. I know you can add repositories using
Using git, I can create branches conceptually , without having to branch my directory
Possible Duplicate: How can I squash my last X commits together using git? I
Using git add command becomes tedious once the file path becomes lengthy. For e.g.
I have just start using git and i can't get it to remember my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.