git merge vs git merge –no-ff (fast-forward vs no fast-forward)

No fastf-orward merge creates additional commit (with message to edit) vs fast-forward where commits are immediately merged. Note also history graph: with no-ff history graph split into 2 branches and combined at additional commit (immediately see from graph there was feature branch and merge - easier to revert as well). However, with ff approach you have only one line with all the commits (need to read log messages which commits are from feature branch) 

mkdir git-merge-no-ff
cd git-merge-no-ff
git init
echo "master: initial create of file" > file.txt
git add file.txt
git commit -m "master: initial create of file" file.txt
git checkout -b "feature-branch"
echo "feature-branch: updated 1x file.txt" >> file.txt
git commit -a -m "feature-branch: updated 1x file.txt"
echo "feature-branch: updated 2x file.txt" >> file.txt
git commit -a -m "feature-branch: updated 2x file.txt"
git checkout master
git merge --no-ff feature-branch
(popup commit message window)

$ git log --decorate --abbrev-commit
commit e5a9e08 (HEAD -> master)
Merge: 0c02667 102bac7
Date: Fri Feb 19 12:05:44 2016 +0100
 Merge branch 'feature-branch' (-no-ff:containing all commits from feature branch)
commit 102bac7 (feature-branch)
Date: Fri Feb 19 12:05:37 2016 +0100
 feature-branch: updated 2x file.txt
commit d44b396
Date: Fri Feb 19 12:05:15 2016 +0100
 feature-branch: updated 1x file.txt
commit 0c02667
Date: Fri Feb 19 12:04:11 2016 +0100
 master: initial create of file

$ git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
* e5a9e08 - Fri, 19 Feb 2016 12:05:44 +0100 (3 minutes ago) (HEAD -> master)
|\ Merge branch 'feature-branch' (-no-ff:containing all commits from feature branch) - Bartosz Wieczorek
| * 102bac7 - Fri, 19 Feb 2016 12:05:37 +0100 (3 minutes ago) (feature-branch)
| | feature-branch: updated 2x file.txt - Bartosz Wieczorek
| * d44b396 - Fri, 19 Feb 2016 12:05:15 +0100 (4 minutes ago)
|/ feature-branch: updated 1x file.txt - Bartosz Wieczorek
* 0c02667 - Fri, 19 Feb 2016 12:04:11 +0100 (5 minutes ago)
 master: initial create of file - Bartosz Wieczorek

VS FAST FORWARD:
git merge --no-ff feature-branch
git log --decorate --abbrev-commit
commit b8cd9ad (HEAD -> master, feature-branch)
Date: Fri Feb 19 12:12:26 2016 +0100
 feature-branch: updated 2x file.txt
commit a1f5f5c
Date: Fri Feb 19 12:12:26 2016 +0100
 feature-branch: updated 1x file.txt
commit 80beaa8
Date: Fri Feb 19 12:12:26 2016 +0100
 master: initial create of file
$ git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
* b8cd9ad - Fri, 19 Feb 2016 12:12:26 +0100 (50 seconds ago) (HEAD -> master, feature-branch)
| feature-branch: updated 2x file.txt - Bartosz Wieczorek
* a1f5f5c - Fri, 19 Feb 2016 12:12:26 +0100 (50 seconds ago)
| feature-branch: updated 1x file.txt - Bartosz Wieczorek
* 80beaa8 - Fri, 19 Feb 2016 12:12:26 +0100 (50 seconds ago)
 master: initial create of file - Bartosz Wieczorek


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s