使用git-svn创建一个新的Subversion分支

5
当使用git-svn与一个“典型”的svn仓库 /trunk,/branches/...,/tags/... 时,我该如何将本地分支推送到 /branches 目录下的一个新分支中?
1个回答

7
假设我们有一个骨架Subversion存储库,其中包含空的trunk/branches/tags/文件夹:
/tmp$ git svn clone -s file:///tmp/svn-repo/ git-svn-repo
Initialized empty Git repository in /tmp/git-svn-repo/.git/
r1 = 80bdcfc0cf248b74b914a1b5f99ab89fb4e31b6c (refs/remotes/trunk)
Checked out HEAD:
  file:///tmp/svn-repo/trunk r1
/tmp$ cd git-svn-repo/
/tmp/git-svn-repo$ git svn branch my-branch Copying file:///tmp/svn-repo/trunk at r1 to file:///tmp/svn-repo/branches/my-branch... Found possible branch point: file:///tmp/svn-repo/trunk => file:///tmp/svn-repo/branches/my-branch, 1 Found branch parent: (refs/remotes/my-branch) 80bdcfc0cf248b74b914a1b5f99ab89fb4e31b6c Following parent with do_switch Successfully followed parent r2 = 56150bbd9d3aec94972ff46d030e30ec726595ab (refs/remotes/my-branch)
下面的解释将在同一存储库的两个视图之间来回切换,一个是整个存储库(而不仅仅是trunk)的Subversion工作副本,另一个是git-svn克隆。为了清晰起见,每个shell提示符的前缀将指示当前目录。
在svn方面,你现在会看到:
/tmp/svn-repo-wc$ svn up
A    branches/my-branch
Updated to revision 2.
你还会在git方面看到新分支:
/tmp/git-svn-repo$ git branch -r
  my-branch
  trunk
要提交到新创建的分支,首先切换到该分支:
/tmp/git-svn-repo$ git reset --hard remotes/my-branch
HEAD is now at 2c9bef2 Create branch my-branch
接下来,我们将创建一个虚拟的git提交:
/tmp/git-svn-repo$ touch on-my-branch
/tmp/git-svn-repo$ git add on-my-branch
/tmp/git-svn-repo$ git commit -m 'First commit to my-branch'
[master b94a0eb] First commit to my-branch
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 on-my-branch
最后将其发送到Subversion:
/tmp/git-svn-repo$ git svn dcommit
提交到file:///tmp/svn-repo/branches/my-branch ...
    A   on-my-branch
已提交r3
    A   on-my-branch
r3 = d3c5ba3e03e5cdee96f470ff4c9898eb7c523ed8 (refs/remotes/my-branch)
当前HEAD和refs/remotes/my-branch之间没有变化
重置为最新的refs/remotes/my-branch

Subversion工作副本给我们确认:

/tmp/svn-repo-wc$ svn up
A    branches/my-branch/on-my-branch
更新到版本3。

根据https://dev59.com/nXVC5IYBdhLWcg3whRgw的说明,现在您可以切换到svn分支而不是执行reset --hard命令:`git checkout -b my-local-branch remote-branch` `# 编辑` `git commit` `git svn dcommit` `git checkout master # 再次在主干上工作` - jackbravo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接