4

I accidentally removed 3 files from both git and my working directory with

git rm -f [file]

when I was only trying to get git to ignore them. Is there any way to undo this command? The files have been changed since my last commit.

Nick Volynkin
  • 14,023
  • 6
  • 43
  • 67
Frank Peelen
  • 55
  • 1
  • 7
  • 2
    The only sure pathway back to a previous state is to go to a commit. If there were none, you can't. Sorry for your loss. – gustafbstrom May 24 '15 at 07:04
  • 1
    Unless you have some other backup, then the changes you made to those files are lost. `git rm` won't normally remove files that have been changed, but the `-f` option overrides that. – Michael Burr May 24 '15 at 07:04
  • 1
    Also this may be the answer for what you were trying to do (ignore changes to files that are being tracked): http://stackoverflow.com/a/17410119/12711 – Michael Burr May 24 '15 at 07:06
  • I see. I had a feeling that'd be the case, but I wanted to make absolutely sure. Thanks! – Frank Peelen May 24 '15 at 07:08
  • possible duplicate of [How to revert a "git rm -r ."?](http://stackoverflow.com/questions/2125710/how-to-revert-a-git-rm-r) – jub0bs May 24 '15 at 07:52
  • possible solution http://stackoverflow.com/questions/14475003/recover-files-after-git-rm-rf – Nick Volynkin Jun 24 '15 at 06:47

1 Answers1

0

Since you used -f, there should be no way in git to get them back. But: if you didn't yet reset the files to a former version, there's a good chance that the actual data still resides on your hard disk.

You can use a software that scans your drive for deleted but recoverable files. There should be some of those programs for each major OS. On Windows I successfully used Undelete360 but there are also other options.

glaed
  • 431
  • 1
  • 7
  • 19