如何使用git merge –squash?
我有一个远程Git服务器,这是我想要执行的场景,
- 
对于每个bug /function我创build一个不同的Git分支,
 - 
我继续在Git分支中使用非官方的Git消息提交我的代码
 - 
在最上面的版本库中,我们必须对官方Git消息的一个bug进行一次提交,
 
那么我怎样才能将我的分支合并到远程分支,这样他们就可以为我的所有签入提交一个提交(我甚至想为此提供提交消息)?
 说你的bug修复分支叫做bugfix并且你想把它合并到master : 
 git checkout master git merge --squash bugfix git commit 
 这将从错误bugfix分支中提取所有提交,将它们bugfix到1提交,然后将其与master分支合并。 
你想合并的南瓜选项。 那就是如果你想一次只做一个分支。
 git merge --squash feature1 
如果你想合并所有的分支在同一时间作为单一的提交,然后首先rebase交互和压缩每个function然后章鱼合并:
 git checkout feature1 git rebase -i master 
挤成一个提交,然后重复其他function。
 git checkout master git merge feature1 feature2 feature3 ... 
最后一次合并是一个“章鱼合并”,因为它合并了很多分支。
希望这可以帮助
终于清除了我的是一个评论显示:
 git checkout main git merge --squash feature 
相当于做:
 git checkout feature git diff main > feature.patch git checkout main patch -p1 < feature.patch git add . 
 当我想合并function分支与105(!!)提交,并把他们全部压扁到一个,我不想git rebase -i origin/master因为我需要分别解决合并冲突为每个中间提交(或者至less是git自己弄不清楚的)。 使用git merge --squash可以获得我想要的结果,即单个提交用于合并整个特性分支。 而且,我最多只需要做一次手动冲突解决。 
 如果你已经把git merge bugfix到main ,那么你可以把你的合并提交压缩成一个: 
 git reset --soft HEAD^1 git commit 
 使用自定义提交将newFeature分支合并到master : 
 git merge --squash newFeature && git commit -m 'Your custom commit message'; 
相反,如果你这样做
 git merge --squash newFeature && git commit 
 你将得到一个提交消息,包含所有可以自定义的newFeature分支提交。 
对于SourceTree
创build一个新function
通过terminal:
 git checkout origin/feature/<featurename> git merge --squash origin/feature/<featurename> 
这没有提交它,让你先审查它。
然后提交,并完成这个新分支的function,并删除/忽略旧的(你开发的)。