Git: Recovering a file that you deleted
You might be doing some spring cleaning to your source code, or you might move files around that you think are unnecessary. Later on, you realize that one of the files you removed was a dependency. Now what? For this, we use git checkout.
If this is you:
...edit files... git add edited-file git commit -m "made changed" git rm seemingly-useless-file git commit -m "removed unreferenced dependency" ... edit file ... realize you dynamically included that file elsewhere..
Then you can simply follow up with:
git checkout 0a323 // the previous revision (hash from `git log`) cp seemingly-useless-file seemingly-useless-file.1 git checkout master mv seemingly-useless-file.1 seemingly-useless-file git add seemingly-useless-file git commit -m "Restored seemingly-useless-file"
You may want to git blame yourself while you’re at it.
If you know of a better way, please let me know.
Untrack Files with Git
When I found this little gem, I couldn’t not (double negative for emphasis) store it for reference.
git rm --cached filename
Don’t worry, it won’t remove your local copy. It just stages it for removal from the history of tracked files.
Reference:
untrack files in git
Git – Install and Configure
Git is a code revision system not much unlike subversion and CVS. One of the best features of git is that it is a distributed revision system, so you can check-in, check-out, commit, revert, etc without ever needing direct access to the central repository. You can work with your repository as if it were a centralized system if need be found. Read more …