Skip to main content

Posts

Showing posts from November, 2016

Git Recover One Deleted File Among Many

Git can include many files in a single commit. You can modify, add, or delete multiple files, then commit the new state of the working directory. What if we deleted multiple files, and now we need to recover in Git some but not all of what has been deleted? Since Git tracks the state of our repository as a series of snapshots (aka Commits) in time, we can recover the file by looking at a past snapshot / commit and “checking out” the resource(s) we must recover. For example: Let's say that a few days ago I deleted several files from the Git repository. I deleted them on my local, committed the change, and pushed to the server. Other developers have done many other commits since then. Now, it turns out one of the files is needed after all, but the others should remain deleted. How to get the one file back? I will show some Git command-line steps to retrieve it. There are other ways, using your IDE, File Explorer, Tortoise or your UI of choice. But the command-l