Let say I create a branch called foo from master and while working on it, I perform a lot of local commits. I am now done with the branch an want to merge it back into master however while I don’t want to squash all commits into just one commit when merging back which I know can be done with:
#from master branch
git merge --squash foo
I stil want to be able to squash some of the commits so that only the important ones are pushed to the origin repository. Now if I know the number of commits I have done since creating the branch, this is easy. All I have to do is:
#assuming I did 20 commits
#while in the foo branch
git rebase -i HEAD~20
And then I can squash the commits I want. The issue is that I generally don’t keep track of the number of times I commit to a branch so if I don’t know that number (and most cases I won’t) I don’t know what to do. Generally I will only need to squash when the branch is done and I am ready to merge back into master so I was wondering if there is a way to get the number of commits since a branch was created?
I’d simply
or whatever you branched from, so the resulting history will appear I started from later version and the merge back will probably be fast-forward (it’s easier to work with, especially since you are rewriting the actual history to logical changesets anyway). But if you want to keep the same base point, you can do
(or whatever you branched from again).