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

4

10

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

Airman answered 14/5, 2013 at 22:48 Comment(0)
G
15

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).

Globe answered 16/5, 2013 at 11:15 Comment(0)
O
1

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!

Obrien answered 14/5, 2013 at 23:8 Comment(0)
W
1

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.

Wasp answered 6/11, 2019 at 22:57 Comment(0)
O
-1

Quite late answer for Jason, but may help the others.

We had the same problem and FOUND A SOLUTION here...

In brief:

  1. type hg heads - you will see head of your changes is stil somewhere in the repository
  2. copy ID of your head and type hg update <id_of_your_head>
Overtire answered 22/12, 2016 at 20:42 Comment(1)
This only works if you committed the changes. In OP's situation (and mine) the discarded changes weren't committed.Convexoconcave

© 2022 - 2024 — McMap. All rights reserved.