Assuming you forked from the master, you don't need to constantly enter yourBranch in the reset step:
git checkout yourBranch git reset --soft HEAD~$(git rev-list --count HEAD ^master) git add -A git commit -m "one commit on yourBranch"
Explanation :
git rev-list --count HEAD ^master counts commits since you made your function branch from master, for example. twenty.git reset --soft HEAD~20 will do a soft reset of the last 20 commits. This leaves your changes to the files, but removes commits.
Usage :
In my .bash_profile, I added an alias for gisquash to do this with one command:
# squash all commits into one alias gisquash='git reset --soft HEAD~$(git rev-list --count HEAD ^master)'
After reset and commit, you need to do git push --force .
Hint :
If you use Gitlab> = 11.0, you no longer need to do this, since it has a compression option when merging branches. 
mles Dec 15 '17 at 5:43 on 2017-12-15 17:43
source share