git-svn:如何通过 git 创建一个新的 svn 分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/266395/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 05:55:37  来源:igfitidea点击:

git-svn: how do I create a new svn branch via git?

gitversion-controlgit-svn

提问by kch

I have a git repository which tracks an svn repository. I cloned it using --stdlayout.

我有一个跟踪 svn 存储库的 git 存储库。我使用--stdlayout.

I created a new local branch via git checkout -b foobar

我通过创建一个新的本地分支 git checkout -b foobar

Now I want this branch to end up in …/branches/foobarin the svn repository.

现在我希望这个分支最终出现在…/branches/foobarsvn 存储库中。

How do I go about that?

我该怎么做?

(snipped lots of investigative text. see question history if you care)

(剪掉了很多调查性文字。如果您关心,请查看问题历史记录)

采纳答案by kch

as of git v1.6.1, git svn branchis available.

从 git v1.6.1 开始,git svn branch可用。

From the git docs:

从 git 文档:

    branch
        Create a branch in the SVN repository.

        -m, --message
            Allows to specify the commit message.

        -t, --tag
            Create a tag by using the tags_subdir instead of the branches_subdir
            specified during git svn init.

Previous versions of git do not provide a way to create an svn branch.

以前版本的 git 不提供创建 svn 分支的方法。

回答by Jesper R?nn-Jensen

I know this question has been answered a while ago, but after reading it, I it might help adding examples of the specific git svn branch command and relate it to a typical workflow.

我知道这个问题不久前已经得到了回答,但是在阅读它之后,我可能会帮助添加特定 git svn branch 命令的示例并将其与典型的工作流程相关联。

Like kch answered, use git svn branch. Here is a full example, (note the -nfor dry-run to test):

就像 kch 回答的那样,使用git svn branch. 这是一个完整的示例,(注意-n要进行试运行):

git svn branch -n  -m "Branch for authentication bug" auth_bug

If this goes well, server replies with answer like this:

如果一切顺利,服务器回复如下:

Copying https://scm-server.com/svn/portal/trunkat r8914 to https://scm-server.com/svn/portal/branches/auth_bug...

复制https://scm-server.com/svn/portal/trunk在r8914到https://scm-server.com/svn/portal/branches/auth_bug...

And without the -nswitch the server probably adds something like:

如果没有-n开关,服务器可能会添加以下内容:

Found possible branch point: https://scm-server.com/svn/portal/trunk=> https://scm-server.com/portal/branches/auth_bug, 8914

Found branch parent: (refs/remotes/auth_bug)

d731b1fa028d30d685fe260f5bb912cbf59e1971

Following parent with do_switch

Successfully followed parent r8915 = 6ed10c57afcec62e9077fbeed74a326eaa4863b8

(refs/remotes/auth_bug)

找到可能的分支点:https: //scm-server.com/svn/portal/trunk=> https://scm-server.com/portal/branches/auth_bug, 8914

找到分支父级:(refs/remotes/auth_bug)

d731b1fa028d30d685fe260f5bb912cbf59e1971

使用 do_switch 跟随父级

成功跟随父 r8915 = 6ed10c57afcec62e9077fbeed74a326eaa4863b8

(参考/遥控器/ auth_bug)

The best part of it, now you can create a local branch based on your remote branch like so:

最好的部分是,现在您可以基于远程分支创建本地分支,如下所示:

git checkout -b local/auth_bug auth_bug

Which means "check out and create local branch named auth_bugand make it follow the remote branch (last parameter) auth_bug

这意味着“签出并创建命名的本地分支auth_bug并使其遵循远程分支(最后一个参数)auth_bug

Test that your local branch works on that remote branch by using dcommitwith --dry-run(-n):

使用dcommitwith --dry-run( -n)测试您的本地分支是否在该远程分支上工作:

git svn dcommit -n

And SVN server should reply with the new branch name:

SVN 服务器应该回复新的分支名称:

Committing to https://scm-server.com/svn/portal/branches/auth_bug...

致力于https://scm-server.com/svn/portal/branches/auth_bug...

回答by Bryan J Swift

@kch I just (7 December 2008) compiled the v1.6.1-rc1 tag of git and it does contain the git svn branch command and the documentation for it. So the v1.6.1 release of git should (hopefully) contain this command.

@kch 我刚刚(2008 年 12 月 7 日)编译了 git 的 v1.6.1-rc1 标签,它确实包含 git svn branch 命令和它的文档。所以 git 的 v1.6.1 版本应该(希望)包含这个命令。