DEV Community

Discussion on: Git Staging Area: Explained Like I'm Five

Collapse
 
crs1138 profile image
Honza

How do I open one of the many sealed boxes find some old code and bring it back to life?

Let's say, I deleted a bunch of files in favour of one that does what all these other files were doing. That was 3 or commits ago. Now, I just remembered that one of the files would be useful to me.

Collapse
 
sublimegeek profile image
Jonathan Irvin

Git checkout

Collapse
 
crs1138 profile image
Honza

Ok, I get that this opens the box. Now my HEAD is in the box, but how do I recover the one file?

Thread Thread
 
sublimegeek profile image
Jonathan Irvin

Well, depends on what you mean by recover. If you checked out the commit, you'll see the version of the file you want. If there's a lot of changes you can make a copy and then paste it over the latest commit. If there's a few, you can revert lines or hunks selectively.