What does it mean to squash commits in Git? Squashing is a way to rewrite your commit history; this action helps to clean up and simplify your commit history before sharing your work with team members. Squashing a commit in Git means that you are taking the changes from one commit and adding them to the Parent Commit.
So the differences are: squash does not touch your source branch ( tmp here) and creates a single commit where you want. rebase allows you to go on on the same source branch (still tmp ) with: a new base.
Right-click on the parent commit and select 'Rebase children of <sha> interactively'. After that, you'll be able to drag and drop to squash commits.
Squashing lets you combine tiny-yet-related commits into a single, meaningful commit. To use the squashing feature in Sourcetree, drag and drop rows on top of one another. Or, you can use the squash with previous option by right-clicking or using the button at the bottom of the dialog.
As of version 1.5, you can now do interactive rebases, which will allow you to squash.
Interactive rebase has been available in SourceTree for Mac since version 1.6 (emphasis mine):
The
git rebase –interactive
command allows you to reorganise your commits after you’ve created them (but before you’ve made them public), and now you can do this inside SourceTree. Combine (squash) multiple commits together, or re-order them, simply by dragging & dropping. You can also change the commit message, or edit the content of the commits. Just right-click on a commit in the log and choose ‘Rebase children of<sha>
interactively’ to kick the process off.
Apparently squashing commits is a feature in SourceTree version 1.6 for the Mac.
However, the feature doesn't seem to be available in the Windows version of SourceTree, which is currently still at version 1.0.8.
You still have the option of using the command line to squash commits:
git rebase -i <sha-of-base-commit>
In the TODO
list, put an s
(for squash) next to commits to squash into the previous commit:
pick e953225 Add meow meow meow
s def892d Add master
To learn more about how to squash commits using the command line, see Squashing Commits, from the FREE online Pro Git book.
Right-click on the parent commit and select 'Rebase children of <sha> interactively'. After that, you'll be able to drag and drop to squash commits.
https://community.atlassian.com/t5/Sourcetree-questions/In-SourceTree-how-do-I-squash-commits/qaq-p/345666#M10317
As of 1.4.1.0, Windows users still don't have squash. However, you can get the same result by hand.
To squash branch A into branch B:
Commit.
1. 2. 3. 4.
* <- [A][C] * <- [A] * <- [A] * <- [A]
| | | |
* * o <- [C] with changes * o <- [C][B] with changes * * <- [C][B] committed
| |/ |/ |/
* <- [B] * <- [B] * *
| | | |
: : : :
You don't need to create C if you won't need to keep the position of A.
I recommend opening gitk
aside while doing these because you can see all detached commits until you close. (I'd like to see this generosity in SourceTree)
At least, reflog is your friend.
To squash your latest commits ,if you want to last 10 commits
1) git reset HEAD~10
2) git add .
3) git commit -am "single commit message for 10 last changes"
4) git push --force
This answer works with most versions of Sourcetree on any platform, because I am using old functionality only. It is quite simple, after you think of it. As usual, it only works before making your work public. I use it to create "tidy" commits in the shared repository, while committing frequently in my own local repository. Assume you are in local branch myfeature
. Suppose you are several commits ahead of branch origin/myfeature
. You can stay within branch myfeature
throughout the procedure, so you will not influence anyone else's work.
Do a "reset current branch to this commit" on the latest published commit. That is the commit labeled origin/myfeature
. A mixed reset will keep all your changes. Be sure to check that your reset is mixed. (If you inadvertedly do a hard reset, you will lose your work...)
Stage your changes (as usual). Don't forget the files you added or deleted on the way!
Commit. Write a good commit message that summarizes all of your own (local) commit messages, because they are lost.
You have squashed everything and cleaned up your local commits in step 1. You are still on your own feature branch, so you haven't influenced anything else. If you feel insecure, label your latest commit before doing anything else. Just for safe keeping. In that way you can always hard-reset to that label in case things go wrong. If everything works out, just remove that label to clean up your commit-history.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With