How to perform rebase (squash) using tortoisegit

GitTortoisegit

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

You can combine two adjacent commits using the GUI as follows. Remember not do combine commits already on the shared repository. See: Right click 2 commits

Solution 3 - Git

Here's what I did using Tortoise Git & storing the repo on Assembla (a service which competes with GitLab, BitBucket, etc).

I decided I wanted to effectively delete my entire commit history, and start the repo over from scratch. I could have deleted the local git folder and the corresponding repo in Assembla, and then recreated it, but thought it was better to figure out how to do this the “right way”.

So, here’s how I achieved it:

  1. Using Tortoise Git, display the repo’s log. Highlight all the commits, right click on them, and select “combine into one commit”.

  2. In the dialog that pops up, delete the commit comment (which becomes a combination of all the prior comments), and replace it with a single comment e.g. REBASE. Then initiate the commit. The local repo will then be effectively started from scratch (with all the files still added to it of course) without having to delete and recreate it.

  3. Unfortunately, you can’t just push it to Assembla. It will reject this, insisting that your “head” is behind the remote branch. So, to solve that first go to the “Settings” page for the repo in Assembla. Enable “Allow –force push”.

  4. Now perform a “forced push”. I don’t know if Tortoise Git has a gui option for this, but it is easy to do via the command prompt:

    cd [your repo folder] git push -f origin

Done!

UPDATE:

To "force push" with TortoiseGit, in the push dialog there are checkboxes to force "known changes" and "unknown changes". I'm not sure what the difference is, but they both result in using the git --force switch. Try "known changes" to begin with.

Solution 4 - Git

  • Go to Show Log, then make a tag at your current commit (e.g. "tmp").
  • Reset hard to the first commit back in history you don't want to change.
  • Toggle All Branches at the bottom of the log, if you don't see all commits.
  • Then select all newer commits and make a right click on them: Cherry Pick selected commits...
  • Now you are in interactive rebase mode. There you can do what is common for interactive rebase.

Solution 5 - Git

You can do this from the Rebase window. This video covers it well: https://youtu.be/qrMubRPkkrE?t=490

As shown in the video:

  1. Right click TortoiseGit/Rebase...
  2. Change Upstream: to FETCH_HEAD
  3. Change Pick ALL to Squash ALL
  4. Click Start Rebase

Solution 6 - Git

One way is: Go to log dialog and select "rebase onto *" and then check the "Force" checkbox and mark the commits for "squash" (e.g. by typing 'q').

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionzerkmsView Question on Stackoverflow
Solution 1 - GitsschuberthView Answer on Stackoverflow
Solution 2 - GitregisbsbView Answer on Stackoverflow
Solution 3 - GitBuvinJView Answer on Stackoverflow
Solution 4 - Gitarmin.miedlView Answer on Stackoverflow
Solution 5 - GitShawnFeatherlyView Answer on Stackoverflow
Solution 6 - GitSvenView Answer on Stackoverflow