henry
henry

Reputation: 177

Git - Get back a single file from a previous commit

I cannot remember exactly what I did, but I think it was running git rm -r --cached *. I wanted to remove all files from staging. To my surprise, the repo's .gitignore file was removed... although I am sure it will not surprise many of you.

How can I get that specific file back from a previous commit?

Upvotes: 1

Views: 56

Answers (2)

Peter Halligan
Peter Halligan

Reputation: 692

You can use git checkout to get a specific file by providing a commit number and the file name.

git checkout [commit-ref] -- [filename]

Git checkout

Upvotes: 3

eftshift0
eftshift0

Reputation: 30307

git checkout HEAD -- .gitignore will put it back on the working tree.

Upvotes: 1

Related Questions