Restoring a file from Git?

The question is related to the question “How to restore Git after fatal file system error?”, but for a single file.

I need to get to last state 2009-07-27 23:58, where I need the file:

  • Sourcetree 1.8.3 Crashes when login at first after install
  • Xcode 5 crashes with SVN version 1.7 - self signed certificate
  • Why is Visual Studio constantly crashing?
  • XCode 5 crash on loading the project
  • Can a git repository be corrupted if a command modifying it crashes or is aborted?
  • github for windows crashing several times a day
  • /Users/henri/BAckup/6-relationdiagram/Normalized_perhaps_DB/simple_schema0.tcuml

    How can I restore the file after a crash?

    ADDED: Where will I find the file? What are they supposed to do?

    Graham’s tip

    $git checkout 63c6844fded9cfcdee14c9330be82557046b3e56 HENRI_suunnittelu_doc/6-relaatiotietokantakaavio/Normalized_perhaps_DB/simple_schema0.tcuml

    William’s tip

    git checkout bee6763b55cf8259438aa575cedbb09d1d02b96a  HENRI_suunnittelu_doc/6-relaatiotietokantakaavio/Normalized_perhaps_DB/simple_schema0.tcuml

  • how can i git clone git://foo.git AGAIN?
  • Moving from SVN to …?
  • adding certain files (images) to git without versioning
  • Removing files using Git GUI
  • ! master -> master (branch is currently checked out) Error in git
  • Unlink of file Failed. Should I try again?
  • 3 Solutions collect form web for “Restoring a file from Git?”

    sometimes i delete a file or directory in my git local and i want to restore just that file. i run the following command:

     git checkout -- filenameOrDirectory

    note the spaces in between.

    If you need to get a single file out of a commit that is in your repository then git checkout will do it for you. Specifically:

    git checkout <sha> <filename>

    will retrieve the file <filename> from the commit <sha> into your current working copy. can be any reference to any commit, so it could be a branch name, a tag name, HEAD^^^^, or anything at all like that that you want…

    Do you have an uncorrupted copy of the repository anywhere? If so, pull from there to your working directory and then checkout the file. You can do:

    git log --since='2009-07-27 23:58' --pretty=oneline -n 1

    to get the hash you want and then get the file via:

    git checkout <file> <hash>

    If you have no uncorrupted working copies of the repository, you might try ‘git fsck’, but your chance of success is small or zero if files have been lost.

    Git Baby is a git and github fan, let's start git clone.