Using Subversion, how can I cut from one file and paste to another preserving history

前端 未结 4 716
长情又很酷
长情又很酷 2021-02-04 07:20

The situation is that I\'ve spent some time messing around with some experimental code. I now want to move part of that code - about 500 lines - into another file, but I don\'t

相关标签:
4条回答
  • 2021-02-04 07:53

    You can merge all revisions (or specific revisions) of one file into another like this

    svn merge sourcefile targetfile -r 0:HEAD
    

    At first I thought one would have to use the --ignore-ancestry option (since both files don't share any common history) but apparently this is not necessary. I tested with svn 1.6.3.

    You are of course very likely to get alot of conflicts markers in the merge result. It may be easier to do the merge by hand (a copy and paste merge as you say), and then run the above merge command with --record-only to tell subversion about it.

    After the merge, the targetfile will have a svn:mergeinfo property which indicates which commits from sourcefile where merged into it. When you examine the log of targetfile, you can see the history of both files by using the --use-merge-history option. TortoiseSVN has the same feature in the form of a checkbox in the log form.

    0 讨论(0)
  • 2021-02-04 07:54

    I don't think you can preserve history in the way you are describing. SVN keeps track of history on a file-by-file basis, and it won't keep track of two separate files that are combined together on the same code line.

    If you started out with two separate files and then combine them together into a third, then the history of both will be preserved. If you combine one into the other, then the history of one of them will be "lost" in the sense that you won't be able to link back to the history of the "deleted" file just from looking at the history.

    I guess what you could do is in the commit message just note that the content from the other file was combined and then commit the delete in the same commit.

    0 讨论(0)
  • 2021-02-04 07:58

    If you want to copy in a new file and delete the old file :

    svn mv
    

    If you want to duplicate in a new file :

    svn copy
    

    If both file already exists :

    # copy/paste with a text editor
    

    You can delete a file an keep its history with :

    svn del
    

    With SVN you cannot keep trace of the history of a merge of two file. You can merge it by hand and keep a trace in the commit message.

    0 讨论(0)
  • 2021-02-04 08:02

    Can't you leave the code in its own file (after trimming the parts you don't want to keep) and include this file into your 'real' source file?

    // file foo.cpp:
    ...
    namespace {
    #  include "util_code.inc"
    }
    

    Not really orthodox, but should work...

    0 讨论(0)
提交回复
热议问题