Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform rebase (squash) using tortoisegit

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?

like image 521
zerkms Avatar asked Sep 21 '12 10:09

zerkms


People also ask

How do I use TortoiseGit?

Right-Click in the File explorer within the repository and select TortoiseGit =>Create Branch. Name it enhancement and select the checkbox Switch to the new branch. Click Ok. Make a change to the file in the enhancement branch and commit the same.

How do you squash commits with interactive rebase?

Squash commits together. Two other commands rebase interactive offers us are: squash ( s for short), which melds the commit into the previous one (the one in the line before) fixup ( f for short), which acts like “squash”, but discards this commit's message.

Is rebase and squash the same?

Merge squash merges a tree (a sequence of commits) into a single commit. That is, it squashes all changes made in n commits into a single commit. Rebasing is re-basing, that is, choosing a new base (parent commit) for a tree.


1 Answers

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.

like image 73
sschuberth Avatar answered Sep 17 '22 14:09

sschuberth