12

I deleted my db folder in a rails application in with git rm -r

I've tried

git reset HEAD

and

git reset --hard HEAD

but the migration files arent coming back. I tried commiting, then running the reset and still nothing.

What should I do?

Nick Volynkin
  • 14,023
  • 6
  • 43
  • 67
ChrisWesAllen
  • 4,935
  • 18
  • 58
  • 83
  • Check here for an answer. I believe it covers your situation. http://stackoverflow.com/questions/953481/restore-a-deleted-file-in-a-git-repo – Jeff Swensen Feb 17 '11 at 01:55

3 Answers3

18

You can checkout the file from the commit where it still exists. Here's how to do it.

git checkout <commit where the file still exists> -- db
# Example:
git checkout 6936142 -- db

# This also works, but if you have a branch named the same as the file or path,
# it will throw an error.
git checkout 6936142 db
htanata
  • 36,666
  • 8
  • 50
  • 57
2

Try git reset --hard HEAD^1 (the commit just before HEAD). Or you can get the hash of a previous known working commit with git log, then git reset --hard <hash>.

William Scott
  • 2,109
  • 1
  • 24
  • 21
2

You can checkout individual files from your last commit or index.

git checkout db/* checks out everything under db from the index

git checkout master db/* checks out everything under db from the head of the master branch

you may be able to salvage most of your stuff that way

read more: git help checkout

Community
  • 1
  • 1
edgerunner
  • 14,873
  • 2
  • 57
  • 69