3

Say I have a number of commits in the feature branch from last commit in master

... - last_commit_in_master - C1 - C2 - .. - C100

Now I want to merge all those commits into a single one.

I know one solution:

  • git rebase -i master
  • replace all the pick except first one. Yoohoo, there is 2,s/pick/squash/ in vim. <-- that's a step I don't like to do each time
  • choose new commit name.

Is there way to do it easier?

RiaD
  • 46,822
  • 11
  • 79
  • 123

2 Answers2

1

Instead of doing squash, replace each except the first with fixup, and then you don't have to choose a new commit name, it just puts them all in the same commit.

1

If you are combining all commits into one, and you want the commit message and time of the last commit.

git reset --soft $(git merge-base HEAD master)
git commit -c ORIG_HEAD

(This will let you re-edit the message if you want to tweak it.)

This will not rebase. Do that in a separate step.

Joseph K. Strauss
  • 4,683
  • 1
  • 23
  • 40