Git:如何避免合并开发分支的中间提交成Master?

时间:2017-06-14 14:59:15

标签: git git-branch git-merge

我是GIT的新手,我想如何避免中间提交,D1-D2-D3 developmaster添加到git merge上的A-B-C(master) & D1-D2-D3-D4(develop) _on merge becomes_ A-B-C-D1-D2-D3-D4(master) 分支?

例如

A-B-C-D4(master)

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

我尝试了master,虽然它添加了新的提交,但所有中间提交也会添加到<a href='...'></a>

2 个答案:

答案 0 :(得分:1)

使用squash merge:var osDevicesList = ( from os in context.Device_OperatingSystem let devicesWithOSCount = ( from d in context.Device_DeviceDetails where d.DOperatingSystemId == os.OperatingSystemID select d.Id ).Count() group devicesWithOSCount by os.OSName into g select new { OS = g.Key, value = g.First() } );

答案 1 :(得分:0)

方法1

更容易(尽管有风险)的方法是软复位所有较新的提交并创建一个包含所有更改的提交。

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

方法2(首选)

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

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