kke
kke

Reputation: 363

Compare two git branches without intermediate commits (i.e. only commits that are accessible from the branches)

Let's assume i have a git master branch and two feature branches on the same commit (feature1, feature2):

A1 -- A2 (master)
       \
        B1 -- B2 (feature1, feature2)

Now i rebase feature2 branch with changes from master:

A1 -- A2 -- A3 -- A4 -- A5 -- A6 (master)
       \                        \
        B1 -- B2 (feature1)      B1 -- B2 (feature2)

And do perhaps some refactorings (B2') and additional changes (B3) on feature2:

A1 -- A2 -- A3 -- A4 -- A5 -- A6 (master)
       \                        \
        B1 -- B2 (feature1)      B1 -- B2' -- B3 (feature2)

What i want to do is get the diff from only the contents of the two feature branches (and not the master branch) in order to see what was refactored and changed on the feature branch, not on master. I.e. i want to get the diff between B1 -- B2 and B1 -- B2' -- B3. I don't care for the changes that were pushed to master in the meantime. Is there a cmd command for that?

Upvotes: 2

Views: 161

Answers (1)

LeGEC
LeGEC

Reputation: 51988

To my knowledge, the git diff command only compares explicit contents, there is no built-in way to combine several patches together.

What you can do is create a temporary branch, and create the content you wish to compare :

# for example :
git checkout feature1
git checkout -b compare1
git rebase A6
git diff feature2

An alternate way to build that content could be to apply patch A2 A6 on top of feature1, or the reverse patch on top of feature2 :

git checkout feature1
git diff A2 A6 | git apply

# or
git checkout feature2
git diff A6 A2 | git apply

# after inspecting the diff : discard these changes
git checkout .

Upvotes: 1

Related Questions