How to perform rebase (squash) using tortoisegit

zerkms picture zerkms · Sep 21, 2012 · Viewed 57.2k times · Source

Cannot get how to perform squash rebase for the current branch. The console command would be

git rebase -i HEAD~2

and then squash as usually. But how to do the same in TGit?

Script to initialize the case

git init .
touch 1
git add 1
git commit -m "1"
touch 2
git add 2
git commit -m "2"
touch 3
git add 3
git commit -m "3"

As a result after squashing we would have 1 commit with 3 files.

Any proposals?

Answer

sschuberth picture sschuberth · Sep 26, 2012

This works for me using TortoiseGit 1.7.12:

  1. Right-click on the working directory where you want to do an interactive rebase and choose TortoiseGit -> Show log from the context menu.
  2. In the appearing "Log Messages" dialog, right-click on the most recent commit that you would not like to rebase anymore and choose Rebase master onto this... from the context menu.
  3. In the appearing "Rebase" dialog, tick the Force Rebase checkbox and then right-click on the commit to choose between Pick, Squash, etc., or tick the Squash ALL checkbox in your case.
  4. Press the Start Rebase button, which on success turns into a Commit button, and then into a Done button. Press all of them.

Note that in your example script you would squash / fixup to the root commit, which is a special case and does not work as described above because the root commit has no parent that you could select in step 2.