Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get git diff for any merged branch

For each defect in code I create separate branch. When defect is fixed I merge this branch in master, so I have history like illustrated below (we see two branches with fixes):

          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 branch start (1) and branch end (2)) or fix2 (diff between (3) and (4)) at any point of time (e.g. for any closed defect in past).

Update: actual question is how to figure out SHA summs of a and d or e and f to perform next obvious diff command diff <commit> <commit>

like image 630
Alexander Nikolayev Avatar asked Jun 06 '12 08:06

Alexander Nikolayev


People also ask

How do you find the difference between two branches?

In order to compare two branches easily, you have to use the “git diff” command and provide the branch names separated by dots. Using this command, Git will compare the tip of both branches (also called the HEAD) and display a “diff” recap that you can use to see modifications.

How do I compare the differences between two branches in GitHub?

Comparing branches is as easy as selecting the “compare to branch” option while perusing the feature branch you'd like to compare to another. The compare to branch option in GitHub Desktop is located under the “Branch” in the main menu at the top of the interface.

How can you tell if two branches are merged?

Find the merge base, and then check if git diff --name-only $merge_base branchA and git diff --name-only $merge_base branchB have anything in common. Otherwise, you'll need a work tree to try the merge in. You could easily create a second one - either clone the repository, or to save space, just create a work tree.


1 Answers

Note: this is equivalent, as detailed in "Not able to think of a case where git diff master..lab and git diff master...lab would be different", to:

 git diff master...defect1-fix-branch

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

git diff dots

(From "git diff doesn't show enough")

like image 182
VonC Avatar answered Oct 15 '22 17:10

VonC