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?
-
1Can't you just clone the original repo and copy the file into your fork?– TheTechRobo the NerdCommented May 30, 2020 at 15:14
-
stackoverflow.com/…– phdCommented May 30, 2020 at 16:32
-
See also stackoverflow.com/questions/215718/…– mattCommented May 30, 2020 at 16:59
-
@TheTechRobo36414519 I can but I was curious if there is a git friendly cleaner way to accomplish this.– cubsnlinuxCommented May 30, 2020 at 19:58
Add a comment
|
1 Answer
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>
.