简体   繁体   English

在现有的 SVN 仓库上使用 git

[英]Use git on existing SVN repo

I work with a legacy svn repo.我使用旧版svn仓库。 However, I would like to enjoy the benefits of git on my local machine.但是,我想在我的本地机器上享受git的好处。

  • The first option is git init the root of my current repo, write code, and independently commit code locally ( git commit ) and remotely ( svn commit ).第一个选项是git init我当前 repo 的根,编写代码,并在本地 ( git commit ) 和远程 ( svn commit ) 独立提交代码。
  • The second option is git-svn , but I don't know if it's worth the troube of learning the nuances of a new tool.第二个选项是git-svn ,但我不知道是否值得学习新工具的细微差别。

How should I go about this?我该怎么办?

I'd very strongly advocate for git-svn .我非常强烈地提倡git-svn Myself and some of my colleagues have attempted to use a Git repro over the top of a Subversion one, and it's a process made of pain and horror.我自己和我的一些同事曾尝试在 Subversion 之上使用 Git 重现,这是一个充满痛苦和恐惧的过程。

Admittedly this is for Subversion 1.6.x;诚然,这是针对 Subversion 1.6.x 的; I suspect it'd be better with 1.7.x, since that only has a single .svn directory.我怀疑 1.7.x 会更好,因为它只有一个.svn目录。

  • Updating from the repository requires pulling the updates from Subversion, then committing them with Git.从存储库更新需要从 Subversion 中提取更新,然后使用 Git 提交它们。 That's slow and tedious (admittedly it's fairly slow with git-svn , but at least that automates the process).这既缓慢又乏味(诚然,使用git-svn时它相当慢,但至少可以使该过程自动化)。

    Plus, either you end up downloading every commit with Subversion and committing it manually to Git, or you end up committing bunches of Subversion commits to the Git repository, and $deity help you if you ever want to work on a Subversion revision between your Git commits.另外,要么你最终使用 Subversion 下载每个提交并手动提交到 Git,要么你最终将一堆 Subversion 提交提交到 Git 存储库,如果你想在你的 Git 之间处理 Subversion 修订, $deity会帮助你提交。

  • Git can't handle empty directories, Subversion requires them for the format of its .svn directories. Git 无法处理空目录,Subversion 要求它们用于其.svn目录的格式。 Which means you need to keep your .svn repositories outside the Git repository, so any git checkout operation will also need a separate svn up .这意味着您需要将.svn存储库保存在 Git 存储库之外,因此任何git checkout操作也需要一个单独的svn up

  • As you note, you'll need to commit everything seperately.正如您所注意到的,您需要单独提交所有内容。

So, using Subversion and Git separately, you'll need to do pretty much every operation in both Git and Subversion.因此,分别使用 Subversion 和 Git,您将需要在 Git 和 Subversion 中执行几乎所有操作。 Which means everything takes longer, and you get all the disadvantages of both systems, while they both do a good job of screwing over each other's advantages.这意味着一切都需要更长的时间,并且您会得到两个系统的所有缺点,同时它们都很好地发挥了彼此的优势。

Use git-svn, it is really simple.使用git-svn,真的很简单。 First clone your repository with git svn clone then you can git svn dcommit your work or git svn rebase it on the latest changes.首先使用git svn clone克隆您的存储库,然后您可以git svn dcommit您的工作或git svn rebase它基于最新的更改。 Make sure your history is always linear by always rebasing your local branches on master so that you can merge them with git merge --ff-only .通过始终将本地分支重新定位在 master 上来确保您的历史始终是线性的,以便您可以将它们与git merge --ff-only

The best way would be migrating to git and throwing away SVN.最好的方法是迁移到git并丢弃 SVN。

However, if that's not an option use git-svn .但是,如果这不是一个选项,请使用git-svn

When commiting to git/svn separately you'll most likely end up commiting to SVN only very rarely which would result in other developers ending up with huge commits.当单独提交到 git/svn 时,你很可能最终很少提交到 SVN,这会导致其他开发人员最终做出大量提交。

You may try SubGit project.您可以尝试SubGit项目。 Install SubGit into your SVN repository;将 SubGit 安装到您的 SVN 存储库中; a pure Git interface (real Git, not git-svn) for the SVN repository will be created.将为 SVN 存储库创建一个纯 Git 界面(真正的 Git,而不是 git-svn)。 After that you may use both of the interfaces: SVN or Git for your repository.之后,您可以使用两种接口:SVN 或 Git 作为您的存储库。

If you have no access to your SVN server, there's another option to recommend: SmartGit client.如果您无法访问您的 SVN 服务器,还有另一个推荐选项: SmartGit客户端。 It behaves similar to git-svn but proposes more features (tags, ignores, EOL-handling, cherry-picks).它的行为类似于 git-svn,但提出了更多功能(标签、忽略、EOL 处理、精选)。

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

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