无缝 git svn 设置
我是一名强大的 git 用户,并且对此感到很高兴。
现在,我被迫使用 svn,但我并不乐意这样做。使用 git svn 还不太舒服。
所以,这是我想要的设置。
- 我使用 git 存储库,即具有许多本地分支的各种方式的 git。
- 我定期在 git 中创建多个分支并合并,让 git 处理所有这些。
- 我想将选定的 git 分支作为 svn 分支发送,并镜像所有内容。
- 当我删除本地 svn 镜像 git 分支时,svn 分支也会被删除。
强调的一点是,我希望 git 完成合并和分支的所有艰苦工作,然后推送到 svn 并使其成为一个商店。
听起来我在要求一份 git-svn 教程。除了我已经经历过很多次了,然而,当我经常执行 git svn rebase 和 git svn commit 时,我会遇到错误,而且它似乎总是单独与 trunk 对话。
我想要的是发送的镜像 svn 命令和镜像分支。
I am a power git user and a happy one at that.
Now, I'm forced to use svn and I am not exactly happy to do so. Not so comfortable using git svn
yet.
So, here is the setup I'd like and want.
- I use a git repo, that is git in all ways with many local branches.
- I create multiple branches in git regularly and merge, let git handle all of it.
- I want to send selected git branch as an svn branch with everything mirrored.
- When I delete a local svn mirrored git branch, the svn branch gets deleted too.
The underlining point is that, I want git to do all the hard work of merge and branch and just push to the svn and make it a store.
Sounds like I'm asking for a git-svn tutorial. Except I have gone thro them many times, and yet, I face errors while I do git svn rebase
and git svn commit
very often and it always seems to talk to trunk alone.
What I want is mirrored svn commands sent and mirrored branches.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅此问题
git svnbranch
简介和该问题有关如何删除远程分支的信息 - 或在下面获取 git svn 基础知识的完整摘要(包括提到的两个问题中的信息)。为了给您提供更完整的教程(涵盖本地和远程分支、提交、合并本地分支的完整设置 - 请参阅水平线下方的分支设置),以下是如何轻松使用 svn 存储库:
git svn clone
进行存储,可以使用参数-s
(stdlayout) 或使用参数--trunk、--tags、--branches
指定 svn 目录中的主干、标签和分支的目录。-s
表示 svn repo 有这样的目录布局如果没有,您可以指定 trunk、branches 和 的位置>tags 以及上面提供的参数。
当您克隆存储库时,您将自动登陆名为 master 的本地分支,该分支将自动跟踪主干。
在这种情况下,您进行提交就像您不知道您使用 git svn 克隆了存储库一样,除非您不推送提交:
git commit 提交到您的分支
更改。您无需担心自己处于
git svn
-repo 中,直到您想要推送更改。根据上面的设置,我们有本地分支 master,它正在跟踪 trunk。因此,在本地 master 分支内进行提交后,可以使用以下命令将它们推送到主干:
git svn dcommit
(在您的本地分支master)(注意
dcommit
中的d)。要测试您提交的位置,请执行
现在到了有趣的部分:在您这边创建被跟踪的分支。非常简单的阅读上面的问题,我只需复制并粘贴示例:
git svnbranch -n -m "Branch forauthentication bug" auth_bug
请注意,此示例具有
-n
标志这只进行一次空运行。删除该标志才能真正做到这一点。该命令在您上面设置的 branches 目录中的 svn 存储库上创建分支 auth_bug,并且git checkout -b auth_bug auth_bug
创建一个本地分支 auth_bug (第一个参数)并让它跟随远程分支 auth_bug (第二个参数),该分支映射到目录
/branches/auth_bug
在 svn 存储库上。远程分支 auth_bug 存在,因为您是使用git svnbranch
命令创建的(并且可以是任何其他已存在的分支)。在这个本地分支 auth_bug 中,当执行
git svn dcommit
时,所有提交都将被推送到分支目录/branches/auth_bug
中的 svn 存储库(通过在命令中附加-n
来测试它。)要删除分支(我以前没有这样做过),看起来
git svn
无法处理这个问题你,所以根据 另一个问题,你必须直接使用以下内容svn
命令:svn rm $URL/branches/the_branch
这将从远程 svn 存储库中删除分支,然后您必须从本地 git 存储库中删除它,具体取决于它是一个分支(如上面的命令)或一个标签:
或者
要使用上游 svn 分支(“拉”)的更改来更新您的分支,您可以使用以下命令在更改之上重新设置您的分支:
git svn rebase
这会在 svn 中获取新的提交,对您的分支进行变基并回放您的本地提交(如果有)。
see this question for a introduction to
git svn branch
and that question for how to delete remote branches - or below for a complete summary of the basics ofgit svn
(including the information from the two questions mentioned).To give you a more complete tutorial (the complete setup to cover local and remote branches, commiting, merging local branches - see below the horizontal line for just the branch setup), here's how to work easily with a svn repo:
git svn clone <url>
, either with paramter-s
(stdlayout) or with the parameters--trunk, --tags, --branches
to specify the directory of the trunk, tags and branches inside the svn dir.-s
means, the svn repo has a directory layout like thisIf not, you can specify the location of the trunk, branches and tags with the arguments provided above.
When you clone the repo, you will automatically land in a local branch called master, which will automatically track the trunk.
In this, you do your commits just like you would not know you cloned the repo with
git svn
, except you do not push commits:git commit
to do commits to your branchgit branch <branch name>
to create local branchesgit merge <branch name>
to merge changes from local branchesYou do not need to worry about you are in a
git svn
-repo, until you want to push your changes.From the setup above, we have the local branch master which is tracking trunk. So after doing commits inside the local master-branch, they can be pushed to the trunk with the following command:
git svn dcommit
(inside your local branch master)(Note the d in
dcommit
).To test where you commits would go, do
git svn dcommit -n
Now comes the interesting part: create branches on your side that are tracked. Really simple reading the question above, I'll just copy and paste the example:
git svn branch -n -m "Branch for authentication bug" auth_bug
Note that this example has the
-n
flag which only does a dry run. Remove that flag to do it for real. The command creates the branch auth_bug on the svn repo in the branches-directory you set up above, andgit checkout -b auth_bug auth_bug
creates a local branch auth_bug (first param) and lets it follow the remote branch auth_bug (second param), which is mapped to the dir
/branches/auth_bug
on the svn repo. The remote branch auth_bug exists, because you created it with thegit svn branch
-command (and could be any other branch already existing).Inside this local branch auth_bug, all your commits will be pushed to the svn repo in the branches dir
/branches/auth_bug
when doinggit svn dcommit
(test it by appending-n
to the command.)To delete a branch (I've not done it before), it looks like
git svn
does not handle this for you, so according to another question, you have to to the following directly using thesvn
command:svn rm $URL/branches/the_branch
This deletes the branch from the remote svn repo, and then you have to remove it from your local git repo, depending on it was a branch (like in the command above) or a tag:
or
To update your branch with changes from the upstream svn branch ("pull"), you can rebase your branch on top of the change with:
git svn rebase
This fetches new commits in svn, rebases your branch and plays back your local commits (if any).
您可以尝试 SubGit 来代替 git-svn。
SubGit 是一个 Git-SVN 双向服务器端镜像。
如果您可以在本地访问 Subversion 存储库,则可以像这样安装 SubGit:
SubGit 将 Subversion 存储库转换为 Git(也可以以相反的方向工作)并安装 SVN 和 Git 挂钩。结果,Subversion 和 Git 存储库是同步的:每次提交和推送都会启动挂钩,立即转换传入的修改。
以下是使用 SubGit 的一些好处:
SubGit 自动将 svn:ignore 属性转换为 .gitignore 文件,将 svn:eol-style 和 svn:mime-type 属性转换为 .gitattributes;
SubGit 自动将合并跟踪信息从 Git 存储库转换为正确的 svn:mergeinfo 属性更新;
人们可以使用任何 Git 客户端来使用 SubGit 支持的 Git 存储库,所有更改都会立即传播到 Subversion 对应版本。
有关更多详细信息,请参阅 SubGit 文档 和 git-svn 比较页面。
下面是标准 Git 操作如何在 Subversion 存储库中体现的描述:
创建分支 foo 并将其推送到原始 Git 存储库:
推送完成后,Subversion 存储库就会获取从 ^/trunk 复制并进行适当修改的 ^/branches/foo 分支。
将分支foo合并到master:
此时,为分支 ^/trunk 创建了一个新修订版,并进行了适当的修改,包括 svn:mergeinfo 更新:
从远程存储库删除分支:
之后 ^/branches/foo 在 SVN 存储库中被删除。
SubGit 是一个商业产品。对于开源和学术项目以及最多 10 名提交者的项目来说,它是免费的。
免责声明:我是 SubGit 开发人员之一。
Intead of git-svn you may try SubGit.
SubGit is a Git-SVN bi-directional server-side mirror.
If you have local access to Subversion repository, you can install SubGit into it just like this:
SubGit converts Subversion repository into Git (it works in opposite direction as well) and installs SVN and Git hooks. As result Subversion and Git repositories are synchronized: every commit and push starts hooks that convert incoming modifications immediately.
Here are some benefits of using SubGit:
SubGit automatically converts svn:ignore properties into .gitignore files, svn:eol-style and svn:mime-type properties to .gitattributes;
SubGit automatically converts merge-tracking information from Git repository to proper svn:mergeinfo property updates;
One may use any Git client to work with SubGit-powered Git repository, all the changes are immediately propagated to Subversion counterpart.
For more details please refer to SubGit documentation and git-svn comparison page.
And here's the description of how standard Git operations are reflected in Subversion repository:
Create branch foo and push it to the original Git repository:
As soon as push is done, Subversion repository gets ^/branches/foo branch copied from ^/trunk with appropriate modifications.
Merge branch foo to master:
At this moment a new revision created for branch ^/trunk with appropriate modifications including svn:mergeinfo update:
Delete branch from remote repository:
After that ^/branches/foo is deleted in SVN repository.
SubGit is a commercial product. It is free for open-source and academic projects and also for projects with up to 10 committers.
Disclaimer: I'm one of SubGit developers.