Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git checkout to restore files from a prior branch: pathspec did not match any file(s) known to git

Tags:

git

I deleted some files from git and now want them back. I am trying to use git checkout to restore the files.

I looked back through my history, and identified the commit where the files were deleted. When I run git checkout <sha of deleting commit> path/to/my/file, I get

error: pathspec 'path/to/my/file' did not match any file(s) known to git.

What am I doing wrong?

like image 812
stochastic Avatar asked Dec 04 '14 21:12

stochastic


1 Answers

Doh. The commit that deleted those files would necessarily not have them anymore. Thus, I need to go one commit further back. Running:

git checkout <sha of deleting commit>^ path/to/my/file

works perfectly

like image 145
stochastic Avatar answered Oct 05 '22 06:10

stochastic