简体   繁体   English

将 master 重新定位到功能分支上?

[英]Rebasing master onto feature branch?

I recently joined a new team and on the team wiki, it asks us to do the follow git workflow我最近加入了一个新团队,在团队 wiki 上,它要求我们遵循 git 工作流程

git checkout -b feature_branch
#do stuff and push if needed
git checkout master
git rebase feature_branch
git rebase -i HEAD~NUMBER_OF_COMMITS_AHEAD

This is different from the rebase workflow I've seen on basically all sources and it also seems to go against the golden rule of rebasing that I saw from this blog post https://www.atlassian.com/git/tutorials/merging-vs-rebasing .这与我在基本上所有来源上看到的变基工作流程不同,它似乎也违反了我从这篇博文 https://www.atlassian.com/git/tutorials/merging-看到的变基黄金法则与变基 Can someone explain what could be the reasons for the workflow my team wiki suggests?有人可以解释我的团队 wiki 建议的工作流程可能是什么原因吗?

Assuming the instructions are accurate, they would appear to be executing a splice of feature into master .假设指令是准确的,它们似乎正在执行一个拼接到master中的feature Suppose we start with this:假设我们从这个开始:

* (HEAD -> master) E
* D
| * (feature) K
| * J
|/  
* C
* B
* A

Now if we checkout master and rebase feature , we get this:现在,如果我们检查masterrebase feature ,我们会得到:

* (HEAD -> master) E
* D
* (feature) K
* J
* C
* B
* A

So the entirety of feature has been incorporated into master at the point where it split off from master .因此,在 master 与master分离的地方,整个feature都被合并到了master中。 Subsequent commits on master have been moved into the future so that they come after the end of feature . master上的后续提交已移至未来,以便它们在feature结束之后进行。 J and K are spliced into the history A, B, C [splice], D, E. J和K拼接成历史A,B,C【拼接】,D,E。

It's hard to imagine what the purpose of that would be, and it's even harder to imagine what the interactive rebase at the end is supposed to accomplish.很难想象这样做的目的是什么,更难想象最后交互式 rebase 应该完成什么。

The opposite move, however, namely to checkout feature and rebase master , would give us this:然而,相反的举动,即 checkout featurerebase master ,会给我们这个:

* (feature) K
* J
* (HEAD -> master) E
* D
* C
* B
* A

That is a sensible thing to do.这是明智的做法。 It brings feature up to date with the current state of master , minimizing the likelihood of conflicts later.它使featuremaster的当前 state 保持同步,从而最大限度地减少以后发生冲突的可能性。 And the interactive rebase would then make sense too, because that's your chance to clean up feature .并且交互式变基也将有意义,因为这是您清理feature的机会。 You would then push feature and make a pull request.然后,您将推送feature并发出拉取请求。 That is the flow that is generally followed.这是通常遵循的流程。

So my guess is that the instructions are just a mistake.所以我的猜测是这些说明只是一个错误。 It's an easy mistake to make if you're not careful, because the sense of the operations checkout X; merge Y一不小心就很容易犯错,因为操作感是checkout X; merge Y checkout X; merge Y is the opposite of the sense of the operations checkout X; rebase Y checkout X; merge Y与操作checkout X; rebase Y checkout X; rebase Y . checkout X; rebase Y The former means "merge Y into X", but the latter means "rebase X onto Y".前者的意思是“将 Y 合并到 X 中”,而后者的意思是“将 X 重新定位到 Y 上”。 I'll bet whoever wrote the instructions was confused by that.我敢打赌,写说明的人对此感到困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将特性分支重新定位到“主”分支上,导致特性分支中推送的更改丢失 - Rebasing feature branch onto 'master' branch resulting in loss of pushed changes in the feature branch 将主分支重新部署到功能分支,重新建立基础后再次发生冲突 - Rebasing a master branch onto a feature branch, getting conflicts again after rebase 将共享主题分支重新部署到母版上 - Rebasing shared topic branch onto master Git:是否将master合并到master上的功能分支和REBASING功能分支上? - Git: Are MERGING master into feature branch and REBASING feature branch on master equivalent? 撤消重新定位功能分支到另一个功能分支 - Undo rebasing feature branch onto another feature branch 在主节点上重新建立功能分支后,提交数量减少 - Number of commits reduced after rebasing feature branch over master 使用基于功能分支的 rebase 提交消息修改,然后合并到 master - Commit message amend using rebasing on feature branch and then merging into master 在变基到 Git 中的 Master 之前与另一个功能分支合并 - Merging with another feature branch before rebasing to Master in Git git 在使用主分支重新设置功能分支之后拉功能分支将恢复重新设置更改 - git pull feature branch just after rebasing feature branch with master branch will revert rebase changes 重新定位到功能分支 - Rebasing into feature branch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM