简体   繁体   English

如何用主分支历史覆盖开发分支

[英]How to overwrite the development branch with the master branch history

Problem 问题

In our workflow we have a development branch which becomes littered with features from time to time. 在我们的工作流程中,我们有一个开发分支,该分支会时不时出现一些功能。 Sometimes those features will never be merged to master because they won't work or the feature has been dropped. 有时,这些功能永远不会合并到母版,因为它们将无法工作或该功能已被删除。

Therefore the development branch consists of unneccessary commits. 因此,开发分支由不必要的提交组成。

Every half a year we try do recreate the development branch. 我们尝试每半年重新创建开发分支。 We remove it and check it out from our actual master branch. 我们将其删除,然后从实际的master分支中签出。 Every developer needs to be aware of this event because they have to switch their local development branch with the newly created origin/development. 每个开发人员都必须意识到这一事件,因为他们必须使用新创建的来源/开发来切换其本地开发分支。

Often enough this just does not work. 通常,这只是行不通的。 Because some developers are ill or on vacation and as they return they skip the email describing this event. 由于某些开发人员生病或度假,他们返回时会跳过描述此事件的电子邮件。 They end up with confusion. 他们最终陷入混乱。

Question

How can we kind of cleanse the development branch to only have those commits that are equal to the master branch. 我们如何清理开发分支,使其仅具有与master分支相同的提交。 Actually it should contain the same commit history as when we would freshly check it out from the master branch. 实际上,它应该包含与我们从master分支中刚签出时相同的提交历史记录。

You could rewrite the history of the development branch to arbitrarily point to the same commit master does, from which point they would have exactly identical history. 您可以重写development分支的历史记录,以任意指向相同的提交master ,从那时起,它们将具有完全相同的历史记录。

git branch -f development master

However, since development is shared, it means that every repo user will have to update its now-obsolete local version of development , and this means conflict resolving... hard to say it'll be any more convenient that the workflow you described. 但是,由于development是共享的,这意味着每个回购用户都将必须更新其现在过时的本地development版本,这意味着解决冲突...很难说,您描述的工作流程将更加方便。

Actually it should contain the same commit history as when we would freshly check it out from the master branch. 实际上,它应该包含与我们从master分支中刚签出时相同的提交历史记录。

If you really want the development branch to be identical to the master branch, then you may reset it: 如果您确实希望development分支与master分支相同,则可以将其重置:

git checkout development
git reset --hard master

But this isn't really an ideal thing to do, because it rewrites the history of the development branch. 但这并不是真正理想的事情,因为它重写了development分支的历史。 Ss you said, some developers might be on vacation and would get a surprise when they come back and pull development . 假设您说过,有些开发人员可能正在休假,当他们回来进行development时会感到惊讶。 Actually, every developer would get hosed, except for the one developer who does the hard reset. 实际上,除了一名执行硬重置的开发人员外, 每位开发人员都会受到威胁。

So, a better plan would be to create a new development branch (with a different name), whose starting point is the master branch. 因此,更好的计划是创建一个新的开发分支(使用不同的名称),其起点是master分支。 Then, each developer may simply checkout this branch fresh from the start, without any issues. 然后,每个开发人员都可以从一开始就简单地检出该分支,而不会出现任何问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM