How to undelete files in Git? [duplicate]


This question already has an answer here:

<ul><li> <a href="/questions/2125710/how-to-revert-a-git-rm-r" dir="ltr" rel="nofollow">How to revert a “git rm -r .”?</a> <span class="question-originals-answer-count"> 11 answers </span> </li> </ul>

Testing with the rm command in Git I ended up removing all my files from my drive.

The command that caused this to happen is the following:

git rm . -r

Now my file system contains only the directories while all the files that I have previously added to Git are missing.

How can I restore all the files from the Git repository?


git checkout .

In general, if it happens again to you, but with a slightly different scenario like only deleted a few files, you can still use the same pattern:

git checkout -- <file_path>

In that case, the output of git status will also help you with providing possible solutions.

<strong>Warning</strong>: For this particular case, you can also run git reset --hard, but the solution above looks a bit cleaner. Do not get used to this command so easily because you might wipe your modifications away in the future accidentally.


If you have no uncommitted changes, you can run these commands (in this sequence):

git reset . git checkout .


Run git reset either soft or hard:

git reset --soft

git reset --hard

EDIT: Apparently only --hard works for it.


  • bind files into one and generate a tag
  • Duplicate Entries in DB
  • IP and domain create different session
  • Delete record on sepecific field value in liferay service builder
  • ReactJs.net server side render failing after publish
  • EF6 and pre-generated views
  • How to Translate texts contained in MsgBox in Inno Setup?
  • How to get to older Xcode beta version?
  • Mapping two workspace folders to the same working directory
  • WooCommerce hook after order is updated?
  • Return to second to last URL in MVC (return View with previous filter conditions applied)?
  • Spring security - same page to deliver different content based on user role
  • 'doc_del_count' bigger than 'doc_count' on CouchDB
  • Classic ASP URL Rewriting
  • Efficient User-Agent Regex to find Safari in Python
  • Portable JRE on Linux - possible?
  • How can I get the choice “H2” back in the H2 consol?
  • Upload file that is in the cpan database
  • How to define and use opencv mat of user type
  • Allowing both email and username for authentication
  • Handling un-mapped Rest path
  • Java applet as stand-alone Windows application?
  • Cassandra Data Model
  • How can I use Kendo UI with Razor?
  • How do I rollback to a specific git commit
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Proper folder structure for lots of source files
  • Load html files in TinyMce
  • Error creating VM instance in Google Compute Engine
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Why joiner is not used after Sequence generator or Update statergy
  • coudnt use logback because of log4j
  • Getting Messege Twice Using IMvxMessenger
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • File not found error Google Drive API
  • How does Linux kernel interrupt the application?
  • Is it possible to post an object from jquery to bottle.py?
  • Python/Django TangoWithDjango Models and Databases