In this post I will someone expert on git try to explain how git merge --no-ff can help us. I have read here http://nvie.com/posts/a-successful-git-branching-model/ (which I personally found to be a really good post) that git merge --no-ff: "This avoids losing information about the historical existence of a feature branch and groups together all commits that together added the feature". So I found it really useful and make some experiments.
The problem is about how can we know from the git log information which commits belong to each feature. For that I did the next experiment. Suppose two users are developing on a software project two different and independent feature (to avoid merge conflicts). From the last stable version we will proceed as this:
git init touch AAA.txt git add AAA.txt git commit -m "My stable software version" //this will simulate our project repository
So from this point the two user (name Alice and Bob) create two different branches and start working on the features:
git branch feature1_Alice git branch feature2_Bob And now Alice and Bob start working and commiting simultaneously. We could simulate his as:
git checkout feature1_Alice touch f1_A1.txt git add f1_A2.txt git commit -m "Solving little bug on feature 1" Bob do two commits following timeline after Alice does this one:
git checkout feature2_Bob touch f2_B1.txt git add f2_B1.txt git commit -m "Starting feature 2" touch f2_B2.txt git add f2_B2.txt git commit -m "feature 2: implementing new functionality" Then Alice finish feature:
git checkout feature1_Alice touch f2_A3.txt git add f2_A3.txt git commit -m "Feature 1 finished"
Then Bob finishes feature2:
git checkout feature2_Bob touch f1_A3.txt git add f1_A3.txt git commit -m "Feature 2 finished"
Now we merge the new feature to the main branch:
git checkout master git log Output:
commit c58dd35054f83c089292d090781438f37feeffa3
Author: Juan
Date: Tue Apr 25 10:30:01 2017 +0200
My stable software version git merge --no-ff feature1_Alice //We put a message on the created commit
Now git log outputs:
commit 50c5d1570fe0c047f72200bd57ef6cef6fa9077e Merge: c58dd35 c136a23 Author: juan Date: Tue Apr 25 10:48:12 2017 +0200
Merging feature 1 to main Merge branch 'feature1_Alice' commit c136a23c49c546e5f48d9d0634e9bc51d67370cd Author: juan Date: Tue Apr 25 10:41:49 2017 +0200
Feature 1 finished commit c9dbb1b49444555fca528f562d3a38143fd521e9 Author: juan Date: Tue Apr 25 10:35:24 2017 +0200
Solving little buf on feature 1 commit 58afad2b46565e614a99d94d1e1aa1c8520f9f2b Author: juan Date: Tue Apr 25 10:35:01 2017 +0200
Starting feature 1 commit c58dd35054f83c089292d090781438f37feeffa3 Author: juan Date: Tue Apr 25 10:30:01 2017 +0200
My stable software version And finally merge feature 2:
git merge --no-ff feature2_Bob git log commit 3f27f78fefb30080ace629e561a242a4f8dbca56 Merge: 50c5d15 2eee0c1 Author: juan Date: Tue Apr 25 10:54:20 2017 +0200
Merging feature 2 to master Merge branch 'feature2_Bob' commit 50c5d1570fe0c047f72200bd57ef6cef6fa9077e Merge: c58dd35 c136a23 Author: juan Date: Tue Apr 25 10:48:12 2017 +0200
Merging feature 1 to main Merge branch 'feature1_Alice' commit 2eee0c1bb732443ae7d6f4893d651abfd558d55a Author: juan Date: Tue Apr 25 10:43:14 2017 +0200
Feature 2 finished commit c136a23c49c546e5f48d9d0634e9bc51d67370cd Author: juan Date: Tue Apr 25 10:41:49 2017 +0200
Feature 1 finished commit cd3bee2906e02df22866ba710891d21eaebb8013 Author: juan Date: Tue Apr 25 10:40:12 2017 +0200
feature 2: implementing new functionality commit c6fdf092b2645f7d4088f9f439e820a9a820b891 Author: juan Date: Tue Apr 25 10:37:39 2017 +0200
Starting feature 2 commit c9dbb1b49444555fca528f562d3a38143fd521e9 Author: juan Date: Tue Apr 25 10:35:24 2017 +0200
Solving little buf on feature 1 commit 58afad2b46565e614a99d94d1e1aa1c8520f9f2b Author: juan Date: Tue Apr 25 10:35:01 2017 +0200
Starting feature 1 commit c58dd35054f83c089292d090781438f37feeffa3 Author: juan Date: Tue Apr 25 10:30:01 2017 +0200
My stable software version Could anyone tel how can I see from the commit history and merge commit which commits influence each feature? I cannot see the advantage commented in that web when we insert alternative commits from different features (or from a feature and master) in time.
The only difference in using --no-ff is that the merge commit have information of which commits have been merged, but that is unseful for tracking the commit history.
Thanks in advance.