Get git diff for any merged branch

For each code defect, I create a separate branch. When the defect is fixed, I merge this branch into master, so I have a story as shown below (we see two branches with corrections):

defect1 fix defect2 fix a---b---c---d e---f / \ / \ ---o---1---x---y---z---2---o---3---w---4---o--- 

The question is how to get diff for fix1 (between the start of branch (1) and the end of branch (2)) or fix2 (the difference between (3) and (4)) at any time (for example, for any closed defect in the past )

Update: the actual issue is determining the SHA amounts from a and d or e and f to execute the next obvious diff diff <commit> <commit>

+7
source share
4 answers

The answer is simple:

 git diff 1..d 

This shows the differences between the branch point of your defect1 fix branch (i.e. 1 ) and ends (i.e. d ).

To find the beginning of the defect1 fix branch, use

 git merge-base master defect1-fix-branch 

as pointed out in this answer: https://stackoverflow.com/a/464829/
This gives you 1 as per the git merge-base documentation.

The end of the defect1 fix branch is simply identified by name. So, after finding all the differences introduced in defect1 fix , you need to do

 git diff 1..defect1-fix-branch 
+6
source

Note: this is equivalent, as described in the section β€œ It is impossible to imagine the case when git diff master..lab and git diff master...lab will be different, ” so that

  git diff master...defect1-fix-branch 

git diff A...B equivalent to git diff $(git merge-base AB) B

git diff dots

(From " git diff is not displayed enough ")

+3
source

What about:

 git diff <commit> <commit> 

If the commit parameters are the SHA checksums of the actual commits.

+1
source

If you want to see what changes are made to the function branch, after combining it, you simply run:

 git diff HEAD^..HEAD 

In the master branches. This shows the differences between the first parent HEAD (merge commit) and HEAD, which actually displays the differences associated with the union of the entire branch of the function introduced in the main branch.

No need to make things complicated :)

0
source

All Articles