Mercurial - revert the uncommitted changes after did "hg update -C"

15,370

Solution 1

Unfortunately, it's right there in hg help update:

options:

-C --clean     discard uncommitted changes (no backup)

The proper workflow would have been to commit your outstanding changes (which would presumably create a new head) and merge your commit with the revisions you wanted to import.

If you don't like having to commit a half-baked set of changes, check out the shelve extension, which is designed exactly for this: It temporarily puts aside all or some of your uncommitted changes, allowing you to run hg operations before you bring them back again. (shelve is not distributed with mercurial, but I think tortoisehg may include it).

Solution 2

Some IDE's, like Intellij will separate from version control keep track of "Local History" I would check for that in a case like this.

Solution 3

Well, let's take a look:

PS C:\dev> hg init foo
PS C:\dev> cd .\foo
PS C:\dev\foo> echo ":)" > file.txt
PS C:\dev\foo> hg add
adding file.txt
PS C:\dev\foo> hg com -m ":D"
PS C:\dev\foo> echo "DDDD" >> .\file.txt
PS C:\dev\foo> hg sta
M file.txt
PS C:\dev\foo> hg up -C
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
PS C:\dev\foo> hg sta
PS C:\dev\foo> dir


    Directory: C:\dev\foo


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         5/14/2013   4:06 PM            .hg
-a---         5/14/2013   4:06 PM         10 file.txt


PS C:\dev\foo> type .\file.txt
:)

It's gone. :( Sorry for the bad news!

Share:
15,370
Jason N
Author by

Jason N

Updated on June 04, 2022

Comments

  • Jason N
    Jason N about 2 years

    I'm new to Mercurial. I did hg status and I saw the files that changed since the last commit have M in front. I then tried hg update -C. Is there any way I can get back the version of the files with M before I did hg update -C? Or am I pretty much screwed? :( since hg update -C discards any changes since the last commit

  • Rudey
    Rudey over 5 years
    This only works if you committed the changes. In OP's situation (and mine) the discarded changes weren't committed.