0

In a project versioned in SVN I need to do a refactoring that consist of moving chucks of code from one file to another. Not to move or rename the whole file, but separating parts of it into another new file.

I would like to preserve the history of that code including changes done before the move. By default SVN just consider this to be some lines removed from one file and some other lines added to another file, but considers those as totally unrelated.

Is there any way to keep the full change history together?

Just for extra detail, I'm looking for something like this question, but for SVN instead of Git.
And not something like this other question, which I already know and refers to a different case.

Community
  • 1
  • 1
Alejandro
  • 7,290
  • 4
  • 34
  • 59
  • Is the code you are moving from one file going into a *new* file or a file that existed already with other code? – Ben Jun 05 '15 at 21:39
  • `svn move` in SVN 1.8.* is *nearest possible* iteration, there are nor big differences in this area w/Git – Lazy Badger Jun 05 '15 at 21:51
  • @Ben In my particular case, it will go into a *new* file (actually, several, but the basic operation is the same). – Alejandro Jun 05 '15 at 23:29
  • @LazyBadger As far as I know, `svn move` will move/rename *whole* files, while I want to move only *part* of a file into a new one while retaining the reference that some lines came from other file. Unless I got it wrong or I'm missing something, it's not what I want here. The linked post about Git says that it can "guess" such code movements. – Alejandro Jun 05 '15 at 23:34
  • SVN in 1.8.* (better) and even 1.7.* (worse) stored **fact of rename** and maintain linking of such files in history. How much you'll change in renamed file *before commit* is another story. See also http://stackoverflow.com/questions/1537616/handling-renames-svn-vs-git-vs-mercurial. BTW, huge refactoring will be a lot easier in Mercurial – Lazy Badger Jun 08 '15 at 06:08

1 Answers1

3

For move piece of code to new file I usually use next approach:

  • copy file to new (svn cp ...)
  • in new file remove all code except moved code
  • in old file remove moved code piece

Then (usually) blame for moved code will show correct authors.

Sergey Azarkevich
  • 2,641
  • 2
  • 22
  • 38
  • Thanks for the tip, sounds more like a workaround but it works! I would look a bit more for when code is moved to *existing* files, when this doesn't cuts it anymore. – Alejandro Jun 09 '15 at 12:39