我一直在用Git做我所有的工作,并将其推送到GitHub。我对软件和网站都很满意,我不希望在这一点上改变我的工作实践。

我的博士导师要求所有学生将作业保存在学校托管的SVN存储库中。我发现了大量关于将现有的SVN存储库下拉到Git中的文档和教程,但没有关于将Git存储库推到新的SVN存储库中的文档和教程。我希望通过结合Git -svn、一个新的分支和rebase以及所有这些美妙的术语来实现这一点,但我是Git新手,对其中任何一个都没有信心。

然后,当我选择时,我希望只运行几个命令将提交推到SVN存储库。我希望继续使用Git,让SVN存储库镜像Git中的内容。

我将是唯一一个致力于SVN的人,如果这有什么不同的话。


当前回答

直接使用git rebase将丢失第一次提交。Git以不同的方式对待它,并且不能对它进行重基。

有一个程序可以保存完整的历史记录:http://kerneltrap.org/mailarchive/git/2008/10/26/3815034

我将在这里转录解决方案,但学分是Björn。

初始化git-svn:

git svn init -s --prefix=svn/ https://svn/svn/SANDBOX/warren/test2

前缀为您提供了像“svn/trunk”这样的远程跟踪分支,这很好,因为如果您只将本地分支称为“trunk”,则不会得到模棱两可的名称。-s是标准trunk/tags/branches布局的快捷方式。

从SVN中获取初始的东西:

git svn fetch

现在查看你的根提交的散列(应该显示一个单独的提交):

git rev-list --parents master | grep '^.\{40\}$'

然后获取空trunk的哈希值commit:

git rev-parse svn/trunk

创建嫁接:

git replace --graft <root-commit-hash> <svn-trunk-commit-hash>

现在,“gitk”应该将svn/trunk显示为主分支所基于的第一个提交。

使移植物永久化:

git filter-branch -- ^svn/trunk --all

掉落移植物:

git replace -d <root-commit-hash>

Gitk应该仍然在master的祖先中显示svn/trunk。

在树干顶部线性化你的历史:

git svn rebase

现在"git svn dcommit -n"应该告诉你它将提交到trunk。

git svn dcommit

其他回答

我需要将现有的Git存储库提交到一个空的SVN存储库。

我是这样做到的:

$ git checkout master
$ git branch svn
$ git svn init -s --prefix=svn/ --username <user> https://path.to.repo.com/svn/project/
$ git checkout svn
$ git svn fetch
$ git reset --hard remotes/svn/trunk
$ git merge master
$ git svn dcommit

它毫无问题地运行着。我希望这能帮助到一些人。

因为我必须使用不同的用户名向SVN存储库授权(我的源使用私钥/公钥身份验证),所以我必须使用——username属性。

最近我不得不将几个Git存储库迁移到SVN上,在尝试了我能找到的所有解决方案之后,最后对我有用的是Mercurial(是的,使用了第三种VCS)。根据这份指南,我提出了以下流程(适用于Linux,但基本思路也适用于Windows)。

The necessary packages: $ sudo apt-get install git subversion mercurial python-subversion Mercurial needs to be configured by adding the following to ~/.hgrc: [extensions] hgext.convert= Create some temporary working directories (I had several repositories to migrate so I created directories for the SVN and Git versions, to keep them separate): $ mkdir svn $ mkdir git Make an empty local SVN repository: $ svnadmin create svn/project Clone the existing Git repository: $ git clone server/path/project.git git/project Let Mercurial do its thing: $ hg convert --dest-type svn git/project svn/project Now the SVN repository should contain the full commit history, but not with original timestamps. If this is not an issue, skip over the next part to step 11. With a little work, the date and time of each commit can be changed. Since my repositories are fairly small, it was feasible for me to do it manually. First, create a pre-revprop-change hook in the SVN repository with the following contents, to allow the necessary property to be modified: #!/bin/bash exit 0; This script has to be made executable: $ chmod +x svn/project/hooks/pre-revprop-change Mercurial created a working copy of the SVN repository, named project-wc, so switch to it and edit the commit times: $ cd project-wc $ svn propedit svn:date --revprop -r 1 Enter the correct date and time (pay attention to timezones!) and save. You should get a message saying "Set new value for property svn:date on revision 1". Now rinse and repeat for every other revision. Optionally check the commit history to make sure everything looks OK: $ svn log -r 1:HEAD Then go back up one level: $ cd .. Dump the repository: $ svnadmin dump svn/project > project.dump And load the dump on your Subversion server. Done!

这个过程可能也可以直接在远程存储库之间工作,但是我发现与本地存储库一起工作更容易。修正提交时间需要做很多工作,但总的来说,这个过程比我发现的任何其他方法都要简单得多。

我想分享一个在WordPress社区中使用的很棒的工具,叫做Scatter

Git WordPress插件和一点理智的分散

这使得用户能够自动将他们的Git存储库发送到wordpress.org SVN。理论上,这段代码可以应用于任何SVN存储库。

我只是想分享一些我的经验和公认的答案。我做了所有的步骤,在我运行最后一步之前,一切都很好:

git svn dcommit

$ git SVN dcommit 使用未初始化的值$u替换/usr/lib/perl5/vendor_perl/5.22/Git/SVN。下午101线。 在/usr/lib/perl5/vendor_perl/5.22/Git/SVN中使用未初始化的值$u(.)或字符串。下午101线。 refs/remotes/origin/HEAD:“https://192.168.2.101/svn/PROJECT_NAME”中没有找到

我找到了线程https://github.com/nirvdrum/svn2git/issues/50,最后我在101行下面的文件中应用了解决方案 /usr/lib/perl5/vendor_perl / 5.22 / Git / SVN.pm

我更换了

$u =~ s!^\Q$url\E(/|$)!! or die

with

if (!$u) {
    $u = $pathname;
} 
else {
       $u =~ s!^\Q$url\E(/|$)!! or die
      "$refname: '$url' not found in '$u'\n";
}

这解决了我的问题。

> SVN,具有完整的提交历史

我有一个Git项目,必须把它移到SVN上。这是我如何做到的,保持整个提交历史。唯一丢失的是原始提交时间,因为libSVN在执行git svn dcommit时将设置本地时间。

Howto:

Have a SVN repository where we want to import our stuff to and clone it with git-svn: git svn clone https://path.to/svn/repository repo.git-svn` Go there: cd repo.git-svn Add the remote of the Git repository (in this example I'm using C:/Projects/repo.git). You want to push to SVN and give it the name old-git: git remote add old-git file:///C/Projects/repo.git/ Fetch the information from the master branch from the old-git repository to the current repository: git fetch old-git master Checkout the master branch of the old-git remote into a new branch called old in the current repository: git checkout -b old old-git/master` Rebase to put the HEAD on top of old-git/master. This will maintain all your commits. What this does basically is to take all of your work done in Git and put it on top of the work you are accessing from SVN. git rebase master Now go back to your master branch: git checkout master And you can see that you have a clean commit history. This is what you want to push to SVN. Push your work to SVN: git svn dcommit

这是所有。这是非常干净的,没有黑客,一切工作完美的开箱即用。享受。