使用 git-svn:拉、合并还是变基?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/582348/
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
Using git-svn: Pull, Merge or Rebase?
提问by Rob Wilkerson
I've been fighting the git/git-svn learning curve and last night, as part of that learning curve, I did something very, very bad. I've since gotten it corrected, but I'm hoping to understand the error my ways.
我一直在与 git/git-svn 学习曲线作斗争,昨晚,作为学习曲线的一部分,我做了一些非常非常糟糕的事情。我已经改正了,但我希望能以我的方式理解错误。
I have an svn repository from which I've cloned the trunk and branches (tags I ignored since we don't work on those). Using git, I created local branches for each of the branches that I currently need to work with:
我有一个 svn 存储库,我从中克隆了主干和分支(我忽略了标签,因为我们不处理这些标签)。使用 git,我为当前需要使用的每个分支创建了本地分支:
$ git checkout -b trunk svn/trunk
$ git checkout -b feature1 svn/branches/development/feature1
$ git checkout -b maint svn/branches/maintenance/previous-version
I made feature1 my active branch and made a few changes before getting pulled away for a few days. I cam back to it yesterday wanted to integrate any changes that had been made to the trunk so that I was working with the latest and greatest. What I did was a complete update of all brances first, via git svn rebase(no one else had worked on the feature1 branch). With everything up to date from my svn repository, I tried to rebase.
我将 feature1 设为我的活动分支并做了一些更改,然后才离开了几天。我昨天回到它想整合对后备箱所做的任何更改,以便我使用最新和最好的。我所做的是首先通过git svn rebase对所有分支进行完整更新(没有其他人在 feature1 分支上工作过)。随着我的 svn 存储库中的所有内容都是最新的,我尝试重新定位。
With feature1 as my active branch, I did a "git rebase trunk" thinking that I would be pulling changes from the trunk intothe feature1 branch. Turns out I was very, very wrong. After merging all of the conflicts, I did a git svn dcommitand found that my changes had been applied to the trunk.
将 feature1 作为我的活动分支,我做了一个“git rebase trunk”,认为我会将更改从主干拉入feature1 分支。事实证明我错了,非常非常错误。合并所有冲突后,我做了一个git svn dcommit,发现我的更改已经应用到主干上。
My first question is simply where was the core error in my thought process? My second is, after much reading and Googling, I see people espousing pulls, merges and rebases. Given the fact that I want to merge the changes applied in one local branch to another local branch, what shouldI have done? What's the best practice for this scenario?
我的第一个问题只是我思考过程中的核心错误在哪里?我的第二个是,经过大量阅读和谷歌搜索后,我看到人们支持 pull、merge 和 rebase。鉴于我想将在一个本地分支中应用的更改合并到另一个本地分支,我应该怎么做?这种情况的最佳实践是什么?
Thanks for your help.
谢谢你的帮助。
采纳答案by Paul
The problem you ran into is that the command line syntax for rebase doesn't match your (very reasonable, IMO) expectations.
您遇到的问题是 rebase 的命令行语法与您的(非常合理的,IMO)期望不符。
$ git checkout feature1
$ git rebase trunk
This sequence adds the unshared feature1 commits onto the HEAD of trunk, and you were expecting that it would place the new trunk commits onto the HEAD of feature1. The syntax actually makes some sense when you know how Git's data model is implemented (which is undoubtedly why it is the way it is). But to me it is the opposite of what I expect, functionally. It's best to learn it as an arbitrary construct and not try to have expectations.
此序列将未共享的 feature1 提交添加到主干的 HEAD 上,并且您期望它将新的主干提交放置到 feature1 的 HEAD 上。当您知道 Git 的数据模型是如何实现的(这无疑是它现在这样的原因)时,语法实际上是有意义的。但对我来说,它在功能上与我的期望相反。最好将它作为一个任意的结构来学习,而不是试图抱有期望。
You're right that you understand how to interact with the SVN repo using git-svn. So ignore what you found in Googling about push and pull and merge -- there's a lot of nearly right discussion by people who act as if push and pull and merge are the same in git and svn. Nearly right is still wrong.
您了解如何使用 git-svn 与 SVN 存储库进行交互是对的。所以忽略你在谷歌搜索中发现的关于推、拉和合并的内容——人们有很多几乎正确的讨论,他们认为推、拉和合并在 git 和 svn 中是相同的。几乎正确仍然是错误的。
回答by Marko
You should use git svn clone -sto clone complete svn tree, including all branches. From then on use git svn rebaseand git svn dcommitin master to deal with svn, and you can create regular git branches for your private use.
您应该使用git svn clone -s来克隆完整的 svn 树,包括所有分支。从此在master中使用git svn rebase和git svn dcommit来处理svn,你可以创建常规的git分支供你私人使用。