Git (unintentional) merge commits

Note: example shows merging NON-CONFLICTING changes from another branch resulting in a merge commit. Note the changes done in master in file.txt were automatically merged to feature branch what could not have been noticed by a developer as there was no conflict. There is a risk that a developer will not include this changes in feature branch (as they were not his changes) what can cause problems.

mkdir git-merge
cd git-merge
git init
echo "master: created" > file.txt
git add file.txt
git commit -am "master: created"
git checkout -b feature-XX
echo "feature-XX: append 1x" >> feature.txt
git add feature.txt
git commit -am "feature-XX: append 1x"
git checkout master
echo "master: append 1x" >> file.txt
git commit -am "master: append 1x"
git checkout feature-XX
echo "feature-XX: append 2x" >> feature.txt
git commit -am "feature-XX: append 2x"
git log --decorate --abbrev-commit
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
$ git merge master # creates unintentional merge commit even though there weren't any conflicts
### MESSAGE ###
Merge branch 'master' into feature-XX

Merge made by the 'recursive' strategy.
file.txt | 1 +
1 file changed, 1 insertion(+)
$ git status
On branch feature-XX
nothing to commit, working directory clean
$ git log --decorate --abbrev-commit
commit 123dc18 (HEAD -> feature-XX)
Merge: 5775ac0 c119837
Date: Wed Feb 24 16:51:36 2016 +0100
Merge branch 'master' into feature-XX
commit 5775ac0
Date: Wed Feb 24 16:51:19 2016 +0100
feature-XX: append 2x
commit c119837 (master)
Date: Wed Feb 24 16:51:18 2016 +0100
master: append 1x
commit a7a3df0
Date: Wed Feb 24 16:51:18 2016 +0100
feature-XX: append 1x
commit 8b430ac
Date: Wed Feb 24 16:51:18 2016 +0100
master: created
$ 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
* 123dc18 - Wed, 24 Feb 2016 16:51:36 +0100 (38 seconds ago) (HEAD -> feature-XX)
|\ Merge branch 'master' into feature-XX - Bartosz Wieczorek
| * c119837 - Wed, 24 Feb 2016 16:51:18 +0100 (56 seconds ago) (master)
| | master: append 1x - Bartosz Wieczorek
* | 5775ac0 - Wed, 24 Feb 2016 16:51:19 +0100 (55 seconds ago)
| | feature-XX: append 2x - Bartosz Wieczorek
* | a7a3df0 - Wed, 24 Feb 2016 16:51:18 +0100 (56 seconds ago)
|/ feature-XX: append 1x - Bartosz Wieczorek
* 8b430ac - Wed, 24 Feb 2016 16:51:18 +0100 (56 seconds ago)
master: created - 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