Git: Recovering a file that you deleted

Posted by Chief on Mar 10, 2010 in Lessons, Reference, Scripts, Tricks and Hacks
No Comments

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.

Tags: , , , , , , , , ,

Untrack Files with Git

Posted by Chief on Dec 8, 2009 in Reference, Scripts, Tricks and Hacks
No Comments

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

Tags: , , ,

Git – Install and Configure

Posted by Chief on Nov 4, 2009 in System Administration
No Comments

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 …

Tags: , , , , , , , ,

Copyright © 2010 cat brain.log | less All rights reserved.
Shades v1.2 theme from BuyNowShop.com.