使用 Subversion,如何从一个文件中剪切并粘贴到另一个保留历史记录 [英] Using Subversion, how can I cut from one file and paste to another preserving history

查看:32
本文介绍了使用 Subversion,如何从一个文件中剪切并粘贴到另一个保留历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况是我花了一些时间来处理一些实验代码.我现在想将该代码的一部分(大约 500 行)移动到另一个文件中,但我不想丢失历史记录,就像我执行简单的文本编辑器剪切和粘贴一样.

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 want to lose the history, as I would if I do a simple text-editor cut and paste.

据我所知,如何将代码从原始文件中分离出来 - svn copy,然后从两个副本中删除不需要的内容.但我不知道如何将该部分副本附加到现有文件中,同时保留两者的历史记录.

As close as I know how to get is separating the code out of the original file - svn copy, then delete unwanted stuff from both copies. But I don't know how to then append that partial copy onto an existing file, keeping the history from both.

这很重要的原因基本上是代码只是非常专业的东西,以帮助实现一些更高级别的功能.我不希望它污染全局命名空间,所以我希望所有这些都在一个文件中,在那里它将被使用并包装在一个匿名命名空间中.

The reason this is important is basically that the code is just pretty specialised stuff, to help implement some higher level functions. I don't want it polluting global namespaces, so I want it all in the one file where it will be used and wrapped in an anonymous namespace.

我意识到这听起来像是将一个分支合并回主干.问题是,没有分支.实验代码并不是从任何东西的副本开始的——它只是一堆从头开始的代码.我要剪切的文件和我要粘贴的文件是完全独立的文件.

I realise this sounds like merging a branch back into the trunk. The thing is, there is no branch. The experimental code didn't start as a copy of anything - it's just a bunch of started-from-scratch code. The file I want to cut from and the one I want to paste into are completely independent files.

我主要使用 TortoiseSVN,但也安装了命令行 subversion.

I mostly use TortoiseSVN, but have command-line subversion installed too.

推荐答案

您可以像这样将一个文件的所有修订(或特定修订)合并到另一个文件中

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

svn merge sourcefile targetfile -r 0:HEAD

起初我认为必须使用 --ignore-ancestry 选项(因为这两个文件不共享任何共同的历史),但显然这不是必需的.我用 svn 1.6.3 测试过.

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.

你当然很可能在合并结果中得到很多冲突标记.手动进行合并可能更容易(如您所说的复制和粘贴合并),然后使用 --record-only 运行上述合并命令以告诉 subversion.

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.

合并后,targetfile 将有一个 svn:mergeinfo 属性,该属性指示来自 sourcefile 的哪些提交合并到其中.当您检查 targetfile 的日志时,您可以使用 --use-merge-history 选项查看两个文件的历史记录.TortoiseSVN在日志表单中以复选框的形式具有相同的功能.

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.

这篇关于使用 Subversion,如何从一个文件中剪切并粘贴到另一个保留历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆