Alexander
Alexander

Reputation: 20234

git checkout last version of deleted file, if available

I have a repo where a file has been deleted locally, and when trying to restore by checking out the latest git commit I noted that the complete folder had been added to .gitignore at some point in the past.

The folder is only needed for the build process on the central machine, and all folder contents except the settings file were completely 3rd-party. To fix some issues, I deleted the folder and unpacked the 3rd party toolkit once again. Redoing the settings from scratch, and especially reissuing the access tokens included therein is laborious and expensive.

To get a head-start, how can I check out the last available version of that config file from my repo, or get the definitive answer that this file was never put into git server?

Upvotes: 1

Views: 110

Answers (1)

mkasberg
mkasberg

Reputation: 17332

Use git log -- path/to/file to find the last commit that touched that file (before it was deleted).

Then, checkout that file from that commit. If the commit hash is aabbcc,

git checkout aabbcc -- path/to/file

Upvotes: 3

Related Questions