Search code examples
mercurialtortoisehg

how to backout to an older version ignoring all versions after that


I have 3 commits which I pushed to the public repository accidentally. I want to revert to an older version (a version before these 3 commits happened) and make it the current code in our public repository. I am using TortoiseHg,version 2.11.1


Solution

  • Option 1

    You can use the strip option as mentioned in the command hg strip is the command This extension has to be enabled Enable the extension by adding the following lines to your .hgrc or Mercurial.ini: [extensions] strip = This option is only suitable if you have access to the central repository where your code is hosted and you have a small group in which you would know if someone have already pulled your changes.

    Option 2

    Another option would be to backout these 3 commits, Since you are using UI,I will attach a screen shot

    Step 1: Right click the unwanted commit and you will see a backout option click that and the wizard wll guide you. if its a merge that you are trying to backout then you have to select which branch to backout to.

    Do the same for the 3 unwanted commits

    enter image description here

    Option 3

    if you have many commits and if its in a named branch following these steps will provide a solution

    1) Close the branch and update to the last good commit you want. 2) Reopen the barch from there by new commit (Named branch can have multiple heads) 3) use hg revert -r and commit

    This will make the working directory exactly as the last good commit you need and ignore the inwanted commits. This will only work if the commits are in a named branch.