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

混江龙づ霸主 提交于 2019-12-02 23:06:40

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.

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.

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.

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...

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!