简体   繁体   English

如何在 Git 中导入并保持更新的 CVS 存储库?

[英]How to import and keep updated a CVS repository in Git?

There is a central repository in CVS, and I would like to use it with Git locally, and then send my changes back to CVS. CVS 中有一个中央存储库,我想在本地将它与 Git 一起使用,然后将我的更改发送回 CVS。

What can I accomplish that on a daily basis?我每天能完成什么?

The tasks I would like to accomplish are:我想完成的任务是:

  • importing branches,进口分支机构,
  • getting history in GIT-like format, and以类似 GIT 的格式获取历史记录,以及
  • exporting back my changes/commits to the centralized server将我的更改/提交导出回中央服务器

BTW, I have also looked at Best practices for using git with CVS .顺便说一句,我还查看了将 git 与 CVS 一起使用的最佳实践 But It didn't work and I couldn't figure out what I missed or did wrong.但它没有用,我无法弄清楚我错过了什么或做错了什么。

What I have done in the past is:我过去所做的是:

Import the CVS repository导入 CVS 存储库

Using:使用:

$ git cvsimport -C target-cvs -r cvs -k -vA authors-file.txt -d $CVSROOT module

Where:在哪里:

  • target-cvs is the directory to keep my local copy of the repository. target-cvs是保存我的存储库本地副本的目录。
  • cvs is the name to use for referencing the remote repository. cvs是用于引用远程存储库的名称。 So, I will have cvs/master , cvs/HEAD , etc. pointed locally by master .所以,我将有cvs/mastercvs/HEAD等由当地指出master
  • authors-file.txt is the file that contains the matches between CVS account and Name+email, each line contains userid=User Name <useremail@hostname> authors-file.txt是包含 CVS account 和 Name+email 匹配的文件,每行包含userid=User Name <useremail@hostname>
  • $CVSROOT is the CVS respository server. $CVSROOT是 CVS 存储库服务器。 If I use an anonymous cloning from some sourceforge repository, then I would use: :pserver:anonymous@project_name.cvs.sourceforge.net:/cvsroot/project_name如果我使用某个 sourceforge 存储库中的匿名克隆,那么我将使用: :pserver:anonymous@project_name.cvs.sourceforge.net:/cvsroot/project_name
  • module is the module inside of the repository I want to clone. module是我要克隆的存储库内的模块。 If the repository has only one module, then likely will be the same as project_name .如果存储库只有一个模块,则可能与project_name相同。

Update the repository更新存储库

It is possible to repeat the command I wrote previously.可以重复我之前写的命令。 In that particular example, it should be run in the parent directory of target-cvs .在那个特定的例子中,它应该在target-cvs的父目录中运行。 To make it easier in the future, you might want to configure some variables (you can read more details in the answer of " How to export revision history from mercurial or git to cvs? " )为了以后更方便,您可能需要配置一些变量(您可以在如何将修订历史从 mercurial 或 git 导出到 cvs?的答案中阅读更多详细信息)

$ git cvsimport

That would be enough to keep the local repository in git synchronized with the remote one in CVS.这足以使git的本地存储库与 CVS 中的远程存储库保持同步。

Daily work日常工作

From now on, every change should go in a local git branch.从现在开始,每个更改都应该在本地 git 分支中进行。 One feature, one branch.一个功能,一个分支。 For this, I use a work flow described in " A successful Git branching model ".为此,我使用了“成功的 Git 分支模型”中描述的工作流程。 The only difference is that master points to CVS, but conceptually the same work flows can be applied here.唯一的区别是master指向 CVS,但从概念上讲,这里可以应用相同的工作流程。 It is just a convention.这只是一个约定。

Once your commit is pushed in CVS, it will be back to master in the next update ( git cvsimport ).一旦您的提交在 CVS 中推送,它将在下一次更新 ( git cvsimport ) 中返回到 master。 Then, you can remove the local branch that implemented that feature.然后,您可以删除实现该功能的本地分支。

For work in progress (in local branches), you should rebase them against master.对于进行中的工作(在当地的分支机构),你应该rebase它们对主人。 Because you have the features separated, it should be easier to solve conflicts.因为您将功能分开,所以解决冲突应该更容易。 The tricky part is when some branches depend on others, but still manageable.棘手的部分是一些分支依赖于其他分支,但仍然可以管理。 Micro commits helps a lot (as in any git work flow).微提交有很大帮助(就像在任何 git 工作流程中一样)。

If every local branch is rebased and master never touched (except for updates), then git cvsexportcommit should just work.如果每个本地分支都重新定位并且 master 从未接触过(更新除外),那么git cvsexportcommit应该可以正常工作。 Remember, it works for one commit.请记住,它适用于一次提交。 It is a bit tedious, but it is better than nothing.这有点乏味,但总比没有好。 Given the previous example the command should be something like:鉴于前面的例子,命令应该是这样的:

$ git cvsexportcommit -vc commit-id

If you only have read-only access to the remote CVS, then you can send the patches by email or make your git repository public, so the commiters can grab your patches to apply them.如果您只有远程 CVS 的只读访问权限,那么您可以通过电子邮件发送补丁或公开您的 git 存储库,以便提交者可以获取您的补丁来应用它们。 Nothing different from a normal work flow of CVS in this case.在这种情况下,与 CVS 的正常工作流程没有什么不同。 Again, in the next update you will see the changes in master .同样,在下一次更新中,您将看到master 中的更改。

With recent version git cvsimport is broken, because of cvsps tool incompatibility .由于cvsps工具不兼容,最新版本的git cvsimport已损坏。

So you've to install cvsps-2.1 .所以你必须安装cvsps-2.1

On OSX you can (having brew ):在 OSX 上你可以(有brew ):

brew tap homebrew/versions
brew install cvsps2
brew unlink cvsps
brew link --overwrite cvsps2

And import on empty git repository as usual, eg:并像往常一样导入空的 git 存储库,例如:

git cvsimport -C RepoName -r cvs -o master -k -v -d:pserver:anonymous@reponame.cvs.sourceforge.net:/cvsroot/path ModuleName

You can also use cvs2git tool which can convert a CVS repository to git.您还可以使用cvs2git工具将 CVS 存储库转换为 git。 However you need to have access to a CVSROOT directory.但是,您需要有权访问 CVSROOT 目录。

Check cvs2git documentation for installation steps.检查cvs2git 文档以了解安装步骤。

Example usage:用法示例:

cvs2git --blobfile=git-blob.dat --dumpfile=git-dump.dat --username=cvs2git /path/to/cvs/repo

This would create two output files in git fast-import format.这将创建两个 git fast-import 格式的输出文件。 The names of these files are specified by your options file or command-line arguments.这些文件的名称由您的选项文件或命令行参数指定。 In the example, these files are named cvs2git-tmp/git-blob.dat and cvs2git-tmp/git-dump.dat .在示例中,这些文件被命名为cvs2git-tmp/git-blob.datcvs2git-tmp/git-dump.dat

These files can be imported into empty git repository by:这些文件可以通过以下方式导入到空的 git 存储库中:

cat git-blob.dat git-dump.dat | git fast-import

Then delete the TAG.FIXUP branch and run gitk --all to view the results of the conversion.然后删除TAG.FIXUP分支,运行gitk --all查看转换结果。

Check for more, by running: cvs2git --help .检查更多,通过运行: cvs2git --help

I believe there is no ready to use recipe in your case.我相信在你的情况下没有现成的食谱。 But, you can try following:但是,您可以尝试以下操作:

  • Manually synching CVS data with Git, or write scripts for that.使用 Git 手动同步 CVS 数据,或为此编写脚本。 They will get information from CVS and put it to Git.他们将从 CVS 获取信息并将其放入 Git。 This will give you some kind of history in Git.这会给你一些 Git 的历史。 Not fully clean, not fully usable, but still.不完全干净,不完全可用,但仍然。
  • Migrate your CVS repository to Git using tools like git cvsimport .使用git cvsimport工具将您的 CVS 存储库迁移到 Git。 And ask Git to pretend to be CVS for other developers, using git cvsserver .并使用git cvsserver要求 Git 假装是其他开发人员的 CVS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM