git-svn 如何知道要提交到哪个分支?

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

How does git-svn know which branch to dcommit to?

svngitgit-svn

提问by John Bachir

My repo is SVN, and I do all development with git. We have a standard layout, and I initialized my local repo with git svn init -s <url to repo>

我的 repo 是 SVN,我使用 git 进行所有开发。我们有一个标准的布局,我用git svn init -s <url to repo>

Here's my workflow for working with branches:

这是我使用分支的工作流程:

# creates a new branch remotely
git svn branch new-branch-name

# switches to a branch or trunk locally
git reset --hard name-of-branch
git reset --hard trunk

# merge changes from trunk into a branch
git reset —hard name-of-branch
git merge trunk
git svn dcommit

That last command above will commit the changes to the branch name-of-branch. My question is, how does git know this? When I do git reset --hard foo, what exactly happens?

上面的最后一个命令会将更改提交到分支名称分支。我的问题是,git 是如何知道这一点的?当我执行 git 时reset --hard foo,究竟会发生什么?

This might just come down to a general question about git. Every time I try to research an answer I get confused about if svn integration is a special case or not.

这可能归结为关于 git 的一般问题。每次我尝试研究答案时,我都会对 svn 集成是否是特例感到困惑。

采纳答案by cdhowie

git-svnwill look up the commit tree for ancestor commits that correspond to active SVN branches (the refs/remotes/...branches that correspond to branches in SVN). It will then dcommit to those.

git-svn将查找对应于活动 SVN 分支(对应于 SVN 中的分支的refs/remotes/...分支)的祖先提交的提交树。然后它会提交给那些。

Note that you should not merge and then dcommit -- SVN's and Git's branching model do not match up, and this kind of thing can fubar your SVN history. You should instead git rebase trunkwhen you are on the branch. (Alternatively, git svn rebase.)

请注意,您不应该先合并然后再提交——SVN 和 Git 的分支模型不匹配,这种事情可能会破坏您的 SVN 历史记录。git rebase trunk当您在分支时,您应该改为。(或者,git svn rebase。)

Also, be aware that the branch you check out prior to the rebase should be a local branch. If it is not, you can create one with git checkout -b local-branch-to-create remote-branch. Then git rebase trunk.

另外,请注意您在 rebase 之前签出的分支应该是本地分支。如果不是,您可以使用git checkout -b local-branch-to-create remote-branch. 然后git rebase trunk

If you want to squash all of the commits that were rebased into one, then do this after the rebase: git reset --soft trunk && git commit.

如果您想将所有重新定位的提交压缩为一个,请在重新定位后执行此操作:git reset --soft trunk && git commit

Once you are happy with the commits that now live on top of trunk, just git svn dcommitto push them to the SVN server.

一旦您对现在位于主干之上的提交感到满意,只需git svn dcommit将它们推送到 SVN 服务器。

回答by Piyush Srivastava

Isn't it as simple as creating a local branch and tracking a remote svn branch? When you do a git svn init --stdlayout url-of-svn-repo, git brings down the whole svn repo, compresses it so that it is operable with git.

是不是像创建本地分支和跟踪远程svn分支一样简单?当你执行 a 时git svn init --stdlayout url-of-svn-repo,git 会关闭整个 svn repo,压缩它以便它可以与 git 一起操作。

After that it is just a matter of fact of doing something like:

在那之后,事实上只是做一些事情:

git checkout -b mybranch -t remotes/mybranch

If you have a local branch tracking a remote branch, git svn dcommitpushes only to the tracked remote branch.

如果您有跟踪远程分支的本地分支,则git svn dcommit仅推送到跟踪的远程分支。

回答by kenorb

Simple way if you'd like to dcommit git master into svn trunk, try the following commands:

如果您想将 git master dcommit 到 svn trunk 中,请尝试以下命令:

git checkout master
git rebase trunk
git svn info # To verify that you're on the right branch
git svn dcommit

The same when on the other branch (e.g. 6.x)

在另一个分支上时相同(例如 6.x)

git checkout 6.x
git rebase 6.x # or git rebase remotes/6.x
git svn info
git svn dcommit