I have occasionally delete some file from the project under git control. After that I made many commits. How to (1) find latest revision in the history, where this file contains and (2) restore only it?
            Asked
            
        
        
            Active
            
        
            Viewed 177 times
        
    3
            
            
        - 
                    possible duplicate of [How to locate a deleted file in the commit history?](http://stackoverflow.com/questions/7203515/how-to-locate-a-deleted-file-in-the-commit-history) – buff Jul 27 '14 at 10:29
- 
                    possible duplicate of [Restore a deleted file in a Git repo](http://stackoverflow.com/questions/953481/restore-a-deleted-file-in-a-git-repo) – John Szakmeister Jul 27 '14 at 10:58
- 
                    How would you identify the file you are looking for? – Thorbjørn Ravn Andersen Jul 27 '14 at 11:31
2 Answers
4
            
            
        To find the commit that deleted the file:
git log --all -- folder/other-folder/file_name.txt
or even just
git log --all -- */file_name.txt
Then just do this:
git checkout (commit hash)^ -- folder/other-folder/file_name.txt
The ^ tells the git to use not that commit, but one prior.
 
    
    
        Max Yankov
        
- 12,551
- 12
- 67
- 135
0
            
            
        If you can identify which commit the deletion took place in, you can try git reflog. reflog will show you all the commits that were made to the repository. Once you find the commit, you can do a git checkout <SHA of commit above>, that will take your working directory to the state of that commit. You can then copy that version of the file manually, do a git checkout <branchname> to go to the required branch and then commit the addition of the file in the next commit.
 
    
    
        gravetii
        
- 9,273
- 9
- 56
- 75
