How can I, with minimum effort, squash all my commits (even with merges and conflict resolutions) to a single one on a feature branch and then rebase on top of the branch where I started developing from? Don't want to redo conflict resolution that's already done. Keep hassle to a minimum.
Suppose the branches we are talking about are master and featureX.
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.
来源:https://stackoverflow.com/questions/54814888/how-to-squash-rebase-in-a-single-shot