【问题标题】:Git: How to avoid intermediate commits of the merged develop branch into Master?Git:如何避免合并的开发分支到Master的中间提交?
【发布时间】:2017-06-14 14:59:14
【问题描述】:

我是 GIT 的新手,我想知道如何避免中间提交说 develop 中的 D1-D2-D3 被添加到 git merge 上的 master 分支?

例如

A-B-C(master) & D1-D2-D3-D4(develop) 

_on merge becomes_ 

A-B-C-D1-D2-D3-D4(master)

它应该看起来像merge 上的A-B-C-D4(master)。理想情况下,我更喜欢A-B-C-E(master),其中 E 是一个新的提交,它是一个merge 提交,将develop 合并到master 上。

我尝试了git merge --no-ff develop,虽然它添加了新的提交,但是所有的中间提交也被添加到了master

【问题讨论】:

标签: git git-branch git-merge


【解决方案1】:

使用 squash 合并:git merge --squash develop

【讨论】:

    【解决方案2】:

    方法一

    更简单(尽管有风险)的方法是软重置所有较新的提交并创建一个包含所有更改的提交。

    git checkout develop
    git reset HEAD~n   # n is the number of commits you want to merge together.
    git commit -am "D4"
    

    方法2(首选)

    常用的方法是 squash 在开发分支中提交,然后将其合并/重新定位到 master。

    git checkout develop
    git rebase -i master
    
    # This will open the editor and let you squash/edit the commits as applicable. For instance
    pick 8705209 D1
    squash 7979797 D2
    squash 9793757 D3 # Use squash to squash commits into the previous one.
    # add the final commit message
    
    git checkout master
    git rebase develop
    

    Rewriting git history

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      • 2013-07-25
      • 1970-01-01
      • 2012-01-25
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多