1

Folks, I need your help!

I tried to push my hg repository to bitbucket for the first time. It didn't work and I thought this was because the project is to huge. Therefore, I wanted to push only one single file. Since I did "hg add *" before, I wanted to revoke this, and typed "hg remove *" and now it DELETED FILES ON MY COMPUTER. But not all of them, only some...

I need these files back, how do I do it? Please tell me they're not gone, please please please.

Thank you so much for your help!!

This is my command history:

  518  hg commit commit_test.txt -m "first commit"
  519  hg add commit_test.txt
  520  hg commit -m "test"
  521  ls -ll
  522  ls -la
  523  cd .hg/ 
  524  ls
  525  ls -la
  526  pico hgrc
  527  cd ..
  528  hg status
  529  hg add commit_test.txt~ 


  530  hg add commit_test.txt
  531  hg commit -m "blabla"
  532  hg push
  533  hg add commit_test.txt
  534  hg commit -m "maaan"
  535  hg status
  536  hg remove *
  537  hg status
  538  hg commit -m "bla"
  539  ls
  540  hg add test.txt 
  541  hg commit -m "test"
  542  hg push
  543  hg revert
  544  hg revert --all
  545  history
  546  hg add *
  547  hg add -r *
  548  hg help add
  549  hg add -S *
  550  cd gui_relabel/
  551  hg add *
  552  cd images/
  553  hg add *
  554  cd ..
  555  hg revert all
  556  hg revert *
  557  history

Here is what hg log gives me:

$ hg log

  changeset:   6:4726f671ae96
  tag:         tip
  user:        KG <...@gmail.com>
  date:        Wed Dec 04 12:21:30 2013 +0100
  summary:     test

  changeset:   5:55b3158def38
  user:        KG <...@gmail.com>
  date:        Wed Dec 04 12:17:19 2013 +0100
  summary:     bla

  changeset:   4:ae0dd836586d
  user:        KG <...@gmail.com>
  date:        Wed Dec 04 12:14:50 2013 +0100
  summary:     blabla

  changeset:   3:0249fdc26fa7
  user:        KG <...@gmail.com>
  date:        Wed Dec 04 12:13:59 2013 +0100
  summary:     test

  changeset:   2:40bdcf4d2104
  user:        KG <...@gmail.com>
  date:        Wed Dec 04 12:12:37 2013 +0100
  summary:     first commit test

  changeset:   1:f9e20020ca1d
  user:        KG <...@gmail.com>
  date:        Sun Nov 10 14:54:46 2013 +0100
  summary:     first commit

  changeset:   0:7a8edcee06ff
  user:        KG <...@gmail.com>
  date:        Mon Nov 04 20:36:41 2013 +0100
  summary:     blabla
user2902965
  • 87
  • 1
  • 1
  • 7

2 Answers2

10

Your files are not gone. Mercurial does not throw away data, that is one of the first rules of the system.

To explain what hg remove did to your files, let us look at the cases one by one. A file in your working copy can be in one out of a handful different states: it can be modified, added, removed, missing, unknown, ignored, or clean.

I've prepared a working copy that looks like this:

$ hg status --all
M a
A b
R c
! d
? e
I f
C g

The files a to g are in the seven states I mentioned above. We can now talk about what happens when you try to remove these files:

  • A modified file (a) is not removed:

    $ hg remove a
    not removing a: file is modified (use -f to force removal)
    
  • An added file (b) is also not removed:

    $ hg remove b
    not removing b: file has been marked for add (use forget to undo)
    
  • A removed file (c) is no longer present in the working copy, so nothing more happens.

  • A missing file (d) is no longer present in the working copy, so nothing more happens.

  • An untracked file (e) is not removed:

    $ hg remove e
    not removing e: file is untracked
    
  • An ignored file (f) is not removed (since it is not tracked):

    $ hg remove f
    not removing f: file is untracked
    
  • A clean file (g) is removed.

The only type of file that hg remove will actually remove from your working copy is a clean file. A clean file is already committed, so the content is safely stored in the repository. You can get it back with hg revert:

$ hg revert g
$ hg status --all
M a
A b
R c
! d
? e
I f
C g

The file g is back with the same content as it had before you removed it.

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
1

It looks like you could run

hg backout 5

You can read more about backout if you like

Blair Conrad
  • 233,004
  • 25
  • 132
  • 111