I have forked a git repo and then later deleted a file in the fork and committed changes to the fork. Is there a way to just get this one file back from the original repo? Is this possible without having to revert my delete commit in the fork?
Asked
Active
Viewed 701 times
0
-
1Can't you just clone the original repo and copy the file into your fork? – TheTechRobo the Nerd May 30 '20 at 15:14
-
https://stackoverflow.com/search?q=%5Bgit%5D+restore+file+from+old+commit – phd May 30 '20 at 16:32
-
See also https://stackoverflow.com/questions/215718/how-can-i-reset-or-revert-a-file-to-a-specific-revision – matt May 30 '20 at 16:59
-
@TheTechRobo36414519 I can but I was curious if there is a git friendly cleaner way to accomplish this. – cubsnlinux May 30 '20 at 19:58
1 Answers
4
Certainly, you can get the file back even from your repo. Remember, your clone contains a copy of the entire history, meaning every commit — and every commit contains all your files at the time of the commit, and no commit is ever lost. You just need to know the SHA of the last commit before the commit that deleted it. Then git checkout <SHA-of-commit> -- <path-of-file>
.

matt
- 515,959
- 87
- 875
- 1,141