You trashed a file in a previous commit
You ruin a file but you only find out about it after a number of other commits. Ouch. Use git log
to find the ObjectID for a commit from before the problem commit. Now we want to get only that file from the commit. For this, we enter:
git checkout ObjectID --<path to file>
(The path to the file is relative to the root of the project.)
You now have the earlier version in the staging area. You can "unstage" it and edit it from the work area.
An alternative to using the ObjectID is to count back from HEAD
, such as:
git checkout HEAD~4 --<path to file>
This just says "go back 4 commits and get the file from there." The two approaches work equally well.