Git: Swipe log branch history and create just one commit

Submitted by Peter Majmesku on Tue, 10/04/2016 - 21:14

Squashing multiple commits to one on merging

Let's say you are done with an new feature. Now you want to merge your feature into the master or develop branch. To keep a good overview within your Git log, you want just 1 Git commit within your log. You do not want all Git commits which you have made during the development in your Git log. Because this would pollute the Git log.

The following way firstly checks out your master branch. Then you are "squashing" all your Git commits to 1 commit. Afterwards you specify the 1 commit which holds your changes.

$ git checkout master
$ git merge --squash yourBranch
$ git commit -m "[#MY-TICKET-ID] Squashed commits."

Swipe Git log for one branch and create one commit

git checkout feature/your-branch
git reset $(git merge-base develop feature/your-branch)
git add -A
git commit -m "one commit on feature/your-branch"

git rebase develop