Recovering files removed by GIT (only in original copy)

I have been working in a project, and in order to have a backup, as well as having syncing my test environment with my production environment, I created a GIT repository (in GitHub).

I have a lot of files in my production environment that I do not need, neither want, in the repository or the test environment. However when I first synchronized I forgot to include them in the .gitignore file(s). So I added the respective lines to the .gitignore files and deleted the files in the test environment.

The problem is that I have just synchronized with the production environment and all those files were removed. None of them is a critical file so, if I cannot recover them it would not be much of a problem. Some are even garbage. However I find many of those files convenient to have around, so I would like to recover them only in production.

(they are not a couple of files but some hundreds of them)

P.S. I still have some files I need to clean up from the repository, however these are critical files in production. What would be the correct way to delete them in the repository without deleting them in production?

  • How do I undelete a file after git rm and pushing to github?
  • git undelete remote branch
  • Undo delete in GIT
  • How to “undelete” a deleted folder in Subversion / TortoiseSVN?
  • “Git Clean -fdx” recovery… possible?
  • How to undelete a file previously deleted in git's history?
  • 2 Solutions collect form web for “Recovering files removed by GIT (only in original copy)”

    You can backup the local repository directory, so there will be no effect in future synchronization with the production repository, so you can retrieve the files.

    After backing up your local repository, issue a git log in backed dir to browse through commit history and locate the commit in which those files were deleted.


    $ git log
    commit 7b37eb6bd946b1fcb28549e83d5bb17d9eee8b56
    Author: A committer <>
    Date:   Wed Nov 20 21:56:09 2013 -0200
        This commit was one after the commit in which files were deleted.
    commit fe14476246c235e674b1e741745ed855454c0105
    Author: A committer <>
    Date:   Wed Nov 20 21:55:18 2013 -0200
        In this commit files were _deleted_.

    Then issue git revert [commit number which deleted files] (i.e. git revert fe1447) and the commit which deleted files will be reverted and those files will be back.

    An interesting tutorial about git is, not too heavy reading and full of good examples.

    If commit abcdef is the one where you removed those files and added them to .gitignore, you can recover the files as they were in the previous commit doing (notice the ^ which means the parent of that commit):

    git checkout abcdef^ -- path/to/removed/file path/to/another/removed/file ...

    If you do a git status next, you’ll have staged for commit (as new files) the files you just recovered.

    Git Baby is a git and github fan, let's start git clone.