How to squash/rebase in a single shot

a 夏天 提交于 2019-11-28 13:14:00

The simplest way I know is

git checkout featureX
git merge -m "Bring latest changes from master" master
# magic starts here
git reset --soft master # put featureX branch pointer on top of master tip
# at this point all the changes related to featureX are on staging area
git commit -m "Feature X in a single shot"

There you go. No rebasing, no squashing.

It sounds like you want to use squash merges.

git checkout master
git merge --squash featureX
git commit

This applies all the changes to master as though you had merged (or rebased) featureX, as a single "non-merge" commit.

There are a couple reasons for this. It is possible to squash and rebase in one step just by doing an interactive rebase, but (1) there's no real need to do that if you're going to squash away every intermediate commit -in that case squash merging is a workable shortcut; and (2) you noted that there may be intervening branching and merging going on within the featureX history that you're merging in; rebase won't deal with that easily.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!