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

标签 git branch git-svn

在使用 git-svn 和一个“典型的”svn 仓库/trunk,/branches/...,/tags/... 如何将本地分支推送到/branches 内的新分支?

最佳答案

假设我们有一个骨架 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)

下面的解释将在同一存储库的两个 View 之间来回切换,整个存储库的 Subversion 工作副本(不仅仅是 trunk)和 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
Committing to file:///tmp/svn-repo/branches/my-branch ...
    A   on-my-branch
Committed r3
    A   on-my-branch
r3 = d3c5ba3e03e5cdee96f470ff4c9898eb7c523ed8 (refs/remotes/my-branch)
No changes between current HEAD and refs/remotes/my-branch
Resetting to the latest refs/remotes/my-branch

Subversion 工作副本给了我们确认:

/tmp/svn-repo-wc$ svn up
A    branches/my-branch/on-my-branch
Updated to revision 3.

关于git - 使用 git-svn 创建一个新的 svn 分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2538533/

相关文章:

git - merge 或 rebase 任意数量的提交

Git merge 错误

version-control - 从分支中的文件夹中清除特殊权限

git - 将 git 分支连接到 GitHub 分支

Git 或 Hg 到 SVN 的桥梁

git - 为什么我总是遇到错误 "Push to origin/master was rejected"?

git - 如何让 bash 补全与别名一起使用?

git - 撤消 Git 跟踪命令

git - 以合理的格式查看git diff-tree

javascript - 获取项目的当前提交并显示它