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
  • git-gui command crashes on macOS Sierra
  • Github App for Mac crashes upon opening
  • Can a git repository be corrupted if a command modifying it crashes or is aborted?
  • XCode 5 crash on loading the project
  • The Git Bash console crashes on open
  • /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
    

  • Monolith git repo vs micro repos
  • Team City pending changes for specific build configuration is not as per default branch
  • How to handle subprojects with autotools?
  • Can I make fast forwarding be off by default in git?
  • Using 'git remote add origin' creates a global remote instead of one local to current directory/repo
  • How not to ignore an item locally which is in .gitignore_global
  • 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.