【问题标题】:Branches out of sync after squash merge壁球合并后分支不同步
【发布时间】:2020-11-05 22:37:33
【问题描述】:

我有一个包含多个提交的 develop 分支。该分支应合并到 master 分支中。 我还希望 master 分支提交历史记录尽可能干净,所以我只想有一个合并条目。因此,我执行以下操作:

git merge --squash develop
git commit

现在来自 develop 的所有更改都在 master 中,并且在 master 上只有一个提交。到目前为止一切顺利:-)

现在的问题是,masterdevelop 似乎不同步。 IE。如果我再次提交 develop,我将无法再将其合并到 master 中。很多冲突都在冒出来。

壁球合并到底应该如何完成,以便之后两个分支同步?

【问题讨论】:

    标签: git merge squash


    【解决方案1】:

    1) 壁球策略旨在避免的“典型”工作流程

    # Initial situation
    
    A---B---C <<< master
             \
              D---E---F <<< develop
    
    # then the merge is done into master
    
    A---B---C-----------G <<< master
             \         /
              D---E---F <<< develop
    
    # no broken history but now master has three (probably noisy) commits
    
    

    2) 您描述的(但不令人满意的)工作流程

    # Initial situation
    
    A---B---C <<< master
             \
              D---E---F <<< develop
    
    # then you squash D, E and F into commit G on master
    
    A---B---C---G <<< master
             \
              D---E---F <<< develop
    
    # as you noticed, at this point master's history is "clean" but develop is out of sync
    
    

    3) 我向您推荐的替代工作流程

    git reset --soft &lt;commit&gt; 正在将 HEAD 移动到其他位置,但将您的更改保留在工作树中,准备好提交(或不提交))doc

    # Initial situation
    
    A---B---C <<< master
             \
              D---E---F <<< develop
    
    # squash your commits D, E and F on develop itself, THEN bring the new commit on master
    
    git checkout develop
    git reset --soft master
    git commit -m "This is my message for these three commits"
    
    A---B---C <<< master
             \
              G <<< develop
    
    git checkout master
    git merge develop
    
    A---B---C---H <<< master
             \ /
              G <<< develop
    
    # now histories are kept related but you have only one (properly remessaged and squashed) commit
    
    

    【讨论】:

    • 感谢您的建议。我在您建议的解决方案中看到的问题是提交历史现在完全消失了。该功能分支在合并到开发后被删除,并且在开发时提交被压缩。所以最后无论是 master 还是 develop 和(删除的)功能分支都没有完整的提交历史。由于特性分支应该被删除并且 master 不应该包含这个详细的历史,develop 将是唯一保留它的地方。因此,挤压那里似乎不是正确的方法。
    • @Boris 哦,我不知道你想保留这些提交。但是,如果您允许这种陈词滥调的类比,那么您要求的是短长棍。如果你确实需要这些提交,为什么不做一个简单的合并呢?这里的挤压是为了什么?
    • 在我阅读的一个 git 教程中,它说 master 上的每个提交都应该对应一个 realease(包括标签和正确的产品版本控制)。因此我认为,develop 是为了积极开发,应该跟踪整个提交历史。另一方面,Master 仅偶尔更新一次,其中包含从开发到该点的所有更改。也许是我弄错了?
    【解决方案2】:

    我的建议是在 merge --squash 提交之后将 master 分支合并到开发分支中。

    所以工作流程如下所示:

    git checkout master 
    git merge --squash develop
    git commit
    
    git checkout develop
    git merge master
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 2010-11-30
      • 1970-01-01
      • 2017-09-23
      • 2014-07-27
      • 1970-01-01
      • 2013-10-11
      相关资源
      最近更新 更多