如何将现有的 CVS 模块导入到现有 git 存储库的子目录中
我正在恢复一个相当旧的代码项目,从我定期使用 CVS 开始,作为我已经使用 git 开发的新项目的一个组件。我仍然可以访问旧项目模块所在的 CVS 存档,因此我打算使用 git-cvsimport 来获取提交历史记录并从那里开始。然而,这只是在当前的 git 存储库中创建一个新的 git 存储库。我完全有可能需要将其作为一个多步骤过程来执行,其中我进入 CVS -> 。新鲜的 git 存储库,然后使用其他东西将其放入现有的 git 存储库中。
在 newproj/newsubdir 中运行它($CVSROOT 已经在我的 shell 配置中正确设置):
git cvsimport -k -o master -u -s \- -A ~/Documents/cvs-authors.txt oldproj
为我提供一个全新的存储库 newproj/newsubdir/.git/ ,其中包含所有正确的提交(注释、时间戳、历史记录),并且 HEAD 位于我要它。
我想要的是历史 CVS 提交就好像它们总是在 newproj/newsubdir/oldproj-file1、newproj/newsubdir/oldproj-file2 等中一样。根据我的经验,git 有能力做这种事情,但我找不到明显适合我情况的方法。
I'm resurrecting a rather old code project, from when I was using CVS regularly, as a component in a new project that I've already been working on using git. I still have access to the CVS archive the old project's module is in, so I was just going to use git-cvsimport to get the commit history and go from there. However, this is just creating a new git repository inside of the current one. It's entirely possible I need to do this as a multistep process where I go CVS -> fresh git repository and then use something else to get it into the existing git repository.
Running this in newproj/newsubdir ($CVSROOT is already correctly set in my shell configuration):
git cvsimport -k -o master -u -s \- -A ~/Documents/cvs-authors.txt oldproj
gets me a brand new repository newproj/newsubdir/.git/ with all of the correct commits (comments, timestamps, history), and with HEAD where I want it.
What I want is for the historical CVS commits to be as if they were always in newproj/newsubdir/oldproj-file1, newproj/newsubdir/oldproj-file2, etc. In my experience, git has the magic to do this kind of thing, but I couldn't find an obvious fit to my situation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你有三个选择。所有这些都从执行干净的 cvsimport 开始,因此请继续执行此操作。
第一意味着外部项目依赖于内部项目,但可能不适合您。
第二个在此 子树合并 中进行了解释方法。这对你来说可能就足够了。
但是如果你喜欢干净的线性历史,你可以做#3并将它们永远纠缠在一起。我不久前在清理项目中做了类似的事情,并有一个许多文档和工具仍然存在。
基本思想是将所有更改分离到可以重建更改的补丁历史记录中。默认情况下,此历史记录按存储库顺序排列,但运行我在帖子中提到的脚本会将补丁按时间顺序重新排列成新序列。
树哈希应该让您知道除了血统之外您没有破坏任何东西。
如果我再次这样做,我可能只会发出一个移植文件并执行一个过滤分支。
You have three options. All of them start with doing the clean cvsimport, so go ahead and do that.
Number one means that the outer project relies on the inner, but is probably not desirable for you.
Number two is explained in this subtree merge howto. It might be good enough for you.
But if you like a nice clean linear history, you can do #3 and tangle them up for good. I did something similar in a cleanup project a while back and have a lot of the documentation and tools still there.
The basic idea was to separate all of the changes into a patch history that would reconstruct the changes. By default, this history is in a sort of repository order, but running the script I mentioned in the post will rearrange the patches into a new sequence in chronological order.
The tree hash should let you know you didn't break anything other than the lineage.
Were I to do this again, I'd possibly just emit a grafts file and do a
filter-branch
.根据 这个组合 git 存储库的答案,弄清楚如何做我想做的事情 ,使用 git filter-branch 使从 CVS 导入的模块直接合并到现有 git 存储库中所需的子目录中
从包含 newproj 的目录开始,现有 git 存储库:
假设 git 存储库中的目标子目录是全新的,或者至少不包含与 CVS 模块中的文件共享名称的文件,合并应该可以顺利进行。
需要注意的是:我上面有 gsed,因为 OS X 附带的 BSD sed 不能像 \t 那样进行字符转义,而且我还没有费心给它起别名。
Figured out how to do what I want based on this answer for combining git repositories, using git filter-branch to make it as if the module imported from CVS had been merged directly into the subdirectory desired in the existing git repository
Starting from the directory containing newproj, the existing git repository:
Assuming the target subdirectory in the git repository was completely new, or at least contained no files that shared names with those in the CVS module, the merge should go off without a hitch.
One caveat: I have gsed above because the BSD sed that comes with OS X can't do character escapes like \t, and I haven't bothered to alias it yet.