开发者

Recover lost files after commit and rollback in Mercurial. (Equivalent of git reflog?)

开发者 https://www.devze.com 2023-04-04 14:24 出处:网络
Commited work. Did a rollback when I wasn\'t on the tip of the repo. Lost files. Looking for git reflog equivalent to save my work.

Commited work. Did a rollback when I wasn't on the tip of the repo. Lost files. Looking for git reflog equivalent to save my work.

Long: So I finish work, then commit.

$ hg commit -A
[...]
adding media/js/fbfriends.js
removing media/js/streams.js
adding media/js/templetizer.js
[...]
$ hg log
$ hg log
changeset:   10:ce3ad416d9a5
tag:         tip
user:        Mihai
date:        Sat Sep 10 22:34:35 2011 -0700
summary:     Save all.

changeset:   9:ceacb7b2192a
user:        Mihai
date:        Sat Sep 10 22:25:34 2011 -0700
summary:     Mootools update.
[...]

Some browsing:

$ hg checkout 8

Okay. Then I wanted to change revision 10. Stupidly, I do:

$ hg rollback
rolling back to revision 9 (undo commit)
$ hg status
[...]
M media/js/mootools.js
R media/js/streams.js
! media/js/fbfriends.js
! media/js/templetizer.js
[...]

WTF? Where did my two files go????

$ hg log
changeset:   9:ceacb7b2192a
tag:         tip
user:        Mihai
date:        Sat Sep 10 22:25:34 2011 -0700
summary:     Mootools update.
[...]

Okay, i'll figure out the .orig files:

$ hg revert --all
[...]
undeleting media/js/streams.js
forgetting media/js/templetizer.js
reverting media/js/mootools.js
[...] // media/js/fbfriends.js doesn't even show up
$ hg status
? media/js/mootools.js.orig
$ hg history
changeset:   9:ceacb7b2开发者_StackOverflow中文版192a
tag:         tip
user:        Mihai
date:        Sat Sep 10 22:25:34 2011 -0700
summary:     Mootools update.

NOOOOOO! I've been royally fscked for being on commit 8 when i did the rollback. Recovery attempts fail:

$ hg checkout 10
8 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ find -name temp
$ hg checkout 9
30 files updated, 0 files merged, 63 files removed, 0 files unresolved
$ find -name temp
$ hg checkout ce3ad416d9a5
abort: unknown revision 'ce3ad416d9a5'!
$ hg checkout ceacb7b2192a
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ find -name temp
$

But, but.. I pushed it in! It should still be somewhere in .hg? Help? git reflog, git checkout blah saved me in a couple instances but are there any mercurial equivalents?

EDIT: Made summary clear. EDIT2: Better title.


Sorry, they are gone.

The help summary for the rollback command is:

roll back the last transaction (dangerous)

and goes on to say:

This command should be used with care. There is only one level of
rollback, and there is no way to undo a rollback. It will also restore the
dirstate at the time of the last transaction, losing any dirstate changes
since that time. This command does not alter the working directory.

Rollback is the only non-extension mercurial command that removes history, and there's been talk about moving it to a disabled-by-default extension like it's similarly destructive cousins strip and purge.

Not that it helps you now, but in the future clone before doing a rollback. Or better yet do a backout instead. Backout adds the inverse of a change, yielding the same resulting tip revision, but with a more accurate history ("I did this", "I undid it").

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号