How not to fast-forward merges in git?
28 Feb 2018TL;DR
git merge --no-ff zoom
Full story
Sometimes, you make a branch just for clarity purpose: for example, you want to add a zoom capacity to your application, so
you create a new branch called zoom
, and you go to that branch.
git checkout -b zoom
You then want to commit your changes concerning the zoom functionality. So you do some
git commit -m 'my zoom is now awesome'
After that, you decide that your modifications are so awesome that they are going to be applied to the master
branch.
So you go back to master
git checkout master
And you want to merge your branch to master… But what? If you just apply them with
git merge zoom
Then, the branch you created for this feature will fast-forward to the master branch, because there were no commits
to the master branch in between. So it will be as if the zoom
branch had never existed (or was for nothing). So, in
order to create a real merge coming from 2 different points in your history, you will have to do a
git merge --no-ff zoom
And tadaaa! You have a real merge, and your zoom
branch now stands out in your history: you know which commits were in
the zoom branch.
See the image below from nvie post to better understand the difference.
Comments