Undo “git checkout HEAD foo.c” in git scm

I did checkout a file with my latest changes to HEAD by mistake..

git checkout HEAD foo.c

that means i lost all my changes that i wanted to commit…

  • Why is '#define alloc_nr(x) (((x)+16)*3/2)' macro used in many cache.h files?
  • Remove Git Credential-osxkeychain
  • How to remove all occurences of a file in index, from all git commits
  • Error when trying to clear cache with a Symfony2 project
  • Automatically cache git credentials from a Windows batch script?
  • Caching remote repository for pip installs
  • is there a way to find these changes in git cache or in some local history?

  • Using bundler, how do you unpack a gem installed via a git repository?
  • Start with a clean slate
  • Understanding Git with XCode and BitBucket
  • Git automatic sync branch in real time
  • Can I live-preview the results of a pull request before accepting it?
  • Which files in .idea folder should be tracked by Git?
  • 2 Solutions collect form web for “Undo “git checkout HEAD foo.c” in git scm”

    if you have not stashed changes to the file while working (and then restoring them) then there’s little you can do about it.

    if you have added the changes of the file using git add (you probably have, because you were about to commit), then the blob should already be in git’s db. you can use git fsck to find dangling objects. look for blobs and inspect all of them – either using git show or git cat-file – (it takes time, i know …), but if you are lucky you will find the contents of your file. use git cat-file blob $hash_of_object > foo.c do to recover the content of your file

    Unless you have committed it, (or stashed it or added it to index) git wouldn’t know about your local changes. So, no.

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