Git-svn:创建并推送一个新的分支/标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2490794/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git-svn: create & push a new branch/tag?
提问by Phillip B Oldham
After cloning an SVN repository using git-svn with the -s
option (git svn clone http://server/repo -s
), how does one create a branch or tag and have pushed to the relevant branch/tag directory in the repository when dcommit
ing?
使用带有-s
选项 ( git svn clone http://server/repo -s
) 的git-svn 克隆 SVN 存储库后,如何创建分支或标签并在dcommit
ing时推送到存储库中的相关分支/标签目录?
For instance; if I were to use git to create a foobar
branch locally (git checkout -b foobar
) how can I have git-svn createthe branch on the server (http://server/repo/branches/foobar
)?
例如; 如果我要使用 git 在foobar
本地创建分支 ( git checkout -b foobar
),我如何让 git-svn在服务器上创建分支 ( http://server/repo/branches/foobar
)?
I'm using Git 1.5.5.6.
我正在使用 Git 1.5.5.6。
Please Note:
请注意:
The accepted method below does not work with Git 1.5.5.6as there is no git svn branch
method. I'm still looking for a solution to this that doesn't involve resolving to working with svn directly.
下面接受的方法不适用于 Git 1.5.5.6,因为没有git svn branch
方法。我仍在寻找不涉及解决直接使用 svn 的解决方案。
回答by mipadi
You can read all the nitty-gritty details in this tutorial, but the gist is basically the following:
您可以阅读本教程中的所有细节,但要点基本上如下:
$ git svn branch -m "Topic branch" my_topic # Create SVN branch called "my_topic"
$ git checkout --track -b my-topic remotes/my_topic # Create the Git branch for "my_topic"
# Hack hack hack...
$ git svn dcommit --dry-run # Make sure you're committing to the right SVN branch
$ git svn dcommit # Commit changes to "my_topic" branch in SVN
回答by pestrella
If you created your local branch before the subversion branch existed and you now want to push your local branch into a subversion branch, you can do the following:
如果您在 subversion 分支存在之前创建了本地分支,并且现在想要将本地分支推送到 subversion 分支中,则可以执行以下操作:
Obtain the svn branch revision assigned to the local branch
获取分配给本地分支的 svn 分支修订版
$ git svn info
$ git svn info
from the output, URL
field would be the current svn branch path and Revision
field would be the subversion revision number
从输出中,URL
字段将是当前的 svn 分支路径,Revision
字段将是颠覆版本号
Create the svn branch from the revision that you created your local branch
从您创建本地分支的修订版创建 svn 分支
$ svn cp http://svn-repo/my_app/trunk@123 http://svn-repo/my_app/branches/feature1
$ svn cp http://svn-repo/my_app/trunk@123 http://svn-repo/my_app/branches/feature1
Fetch the new svn branch so that your git repo knows about it
获取新的 svn 分支,以便您的 git repo 知道它
$ git svn fetch
$ git svn fetch
The svn branch should now be added as a remote in your git repo
$ git branch -a
* feature1
master
remotes/feature1
svn 分支现在应该作为远程添加到你的 git 仓库中
$ git branch -a
* feature1
master
remotes/feature1
At this point your remote will still be trunk. You need to point your local branch to the new remote branch. You can do this by rebasing your local branch from the remote branch:
$ git rebase remotes/feature1
此时您的遥控器仍将是主干。您需要将本地分支指向新的远程分支。您可以通过从远程分支重新设置本地分支来做到这一点:
$ git rebase remotes/feature1
Now that your local branch refer to your remote branch, you can commit your changes onto it. First do a dry run so you are confident that your changes will go into your remote branch:
$ git svn dcommit --dry-run
Commiting to http://svn-repo/my_app/branches/feature1
现在您的本地分支引用了您的远程分支,您可以将更改提交到它上面。首先进行试运行,以便您确信您的更改将进入您的远程分支:
$ git svn dcommit --dry-run
Commiting to http://svn-repo/my_app/branches/feature1
Now you may commit changes to your remote branch
$ git svn dcommit
现在您可以将更改提交到远程分支
$ git svn dcommit
Most how-tos will tell you to branch subversion first and then create a local branch which tracks the remote branch. But I often don't decide ahead of time whether my local branch should track a remote branch. Often I branch locally, and make changes without any intention of pushing to a remote branch. If I later decide to commit my local branch into a remote branch I perform the steps above.
大多数操作指南会告诉您首先对 Subversion 进行分支,然后创建一个跟踪远程分支的本地分支。但是我通常不会提前决定我的本地分支是否应该跟踪远程分支。我经常在本地分支,并在无意推送到远程分支的情况下进行更改。如果我后来决定将我的本地分支提交到远程分支,我将执行上述步骤。
回答by yngve
I just wanted to point out that you shouldn't rebase onto your recently created branch from stuff you already have in a different git branch. git svn dcommit will then afterwards push to trunk it seems. At least that was a problem for me.
我只是想指出,您不应该从不同 git 分支中已有的内容重新创建到最近创建的分支。git svn dcommit 之后似乎会推送到主干。至少这对我来说是个问题。
Instead, if you want to pull changes from an old git branch onto this new svn branch, use e.g. cherry-pick.
相反,如果您想将旧 git 分支中的更改拉到这个新的 svn 分支上,请使用例如cherry-pick。