looking through old code with git log -p

I just found myself wishing that I hadn’t deleted some dead code, because I wanted to use the same technique I’d used earlier. Now, if someone else had been in my position, and refused to delete it, because they wanted to be able to look at it later, I would have suggested that they learn to use their version control system better. So what did I need to learn to do? That’s right: learn git better.

After googling, I found that with the -p flag, git log can be made to show patches. I ran git log -p admin.py, since I knew which file used to contain the code I wanted to look at. It brought up all the changes made to that file, including when I created it, in my pager. I searched for get_urls, because I wanted to find where I had set up a custom admin view in django. It came right up! I copied it and pasted it back into the file. Problem solved.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.