cat brain.log | less

Getting it down on `paper`

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.

 

Comments

No comments so far.

(comments are closed)