views:

101

answers:

5

Whenever someone asks what to do with code that is no longer needed the answer is usually "delete it, restore it from source control if you need it back".

Now how do I find that piece of source code in the repository? Let's limit scope to SVN for simplicity - I suspect that using any other source control system will not make much difference in this aspect (correct me if I'm wrong).

If I delete that code and commit the changes it will no longer be in the latest revision. How do I find it without exporting each revision and searching thoroughly (which is nearly impossible)?

+2  A: 

The way I do it is to think of a date when I knew the missing code was active, and fetch the entire source tree as it was on that date. If I get the date wrong, I'll go x day/weeks/months either side until I zero in on it.

svn checkout --revision {2002-02-17}
Paul Dixon
+4  A: 

You need to use a difference tool, most svn repositories have them. Right click on the file you want to rollback and choose 'diff' or 'difference' or similar (spending on implementation) and then it will ask to compare the current version with an earlier version - if you know the approximate date of the earlier version then choose that version (the date/time stamps are usually obvious) and you will see the two versions side by side. You can then choose which bits are different (usually coloured red) right click on them and choose to integrate them.

The client tool you are using for SVN will determine the details.

amelvin
+3  A: 

Another way is to search the log messages - you presumably left a comment somewhat along the lines of:

Removed XYZ functionality

when you made the change.

anon
This is one usecase that helps me teach the juniors how important it is to use descriptive commit messages. One has to experience the pain of finding something in history at least one time, before it sinks in.
Ether
+1  A: 

Presumably, the code comments or revision comments have keywords to target the code fragment you are looking for:

SVN Query - http://svnquery.tigris.org/

"SvnQuery is a fast full text search engine for subversion repositories. It searches every file in every revision. Not only the content of a file is indexed, but also its complete metadata like path, author, comments and properties. A simple, Google-like web frontend is provided, but it is expected that the query library and indexing mechanism can be reused in other frontends, e.g. a web service or a Visual Studio Plug-In.

SvnQuery is implemented in C# 3.0 and ASP.NET is used for the web frontend. The full text search is done by Lucene.Net which delivers an astonishing performance. ..."

The query language is described here:
http://svnquery.tigris.org/servlets/ProjectProcess?pageID=o0dpdE&freeformpage=SvnWebQueryHelp

Bert F
+1  A: 

The most correct answer is: you can't. There are methods to help you with that task, but it is impossible to do the automatically, because:

  • you don't know which files it is in
  • you don't know the source code or parts of it
  • you can't remember when the code removal happened.
  • ...

A computer cannot read our minds. That said, there are of course other tools that help you, such as the mentioned ones, or graphical front ends like trac (which I like very much for that purpose).

Patrick