Git Diff between two commits/changeset without including merge commit changes

Viewed 80

How to take combined Git diff between 2 commit changesets without including the changes made by merge commits.
For ex :

Commit-1a
File - gitdiff.js Changes

function check(){ 
            var a=10;  
            console.log(a);  
        }

Commit-2b (Merge commit)
File - gitdiff.js
Changes

function merge(){ 
            console.log(“inside merge”);   
        }   
        function mergechange(){ 
            console.log(“inside mergechange”);  
        }

Commit-3c
File - gitdiff.js
Changes

function lastfn(){  
            console.log(“inside lastfn”);   
        }

File Content after 3 commits

function merge(){   
            console.log(“inside merge”);   
        }       
        function check(){   
            var a=10;   
            console.log(a);    
        }
    
function mergechange(){    
            console.log(“inside mergechange”);    
        }    
        function lastfn(){    
            console.log(“inside lastfn”);    
        }

When I am giving git diff between commit 1a and commit 3c, I want the output diff like the following.

Git diff commit-1a commit-3c
File - gitdiff.js
Changes

function check(){    
    var a=10;    
    console.log(a);    
}   
function lastfn(){    
    console.log(“inside lastfn”);    
}

Is there anyway to get the output like the above without including the merge changes ?

1 Answers

You cannot do what you want.

Git stores project states, and git diff can only show changes between project states. For git diff it is totally irrelevant what the relation between the two states is, and whether there are any other project states between them, or whether one of them is a merge.

Related