问题描述:

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?

网友答案:

Don't do any of the previous! Just combine 2 commits using the interface. Remember not do combine commits already on the shared repo. See:

网友答案:

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.

网友答案:

Here's what I did using Tortoise Git & storing the repo on Assembla (which is apparently via similar to GitHub).

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.

网友答案:

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').

相关阅读:
Top