How to check if two branches changed the same line (automatically)

Viewed 119

Imagine that we created two branches from master, branch1, and branch2.

How could we detect using git that branch1 and branch2 changed the same line?

We do not care about intermediate commits in the new branches. We just need to check the difference between branch1 and master and the differences between branch2 and master and check if they changed any common line.

Thanks in advance.

Ps: we cannot cherry-pick all the commits in the branches in order to detect possible conflicts, this approach would produce false positives.

1 Answers

If you want to view the diffs, you can compare :

git diff master...branch1    # three dots

and

git diff master...branch2

Say branch1 (resp. branch2) forked from master at commit c1 (resp. c2).

You could try to apply the changes brought by branch1 on top of c2, and see how this compares with the content of branch2.

Here is one way to do that :

# create a temporary branch 'tmp1' starting at the same commit as branch1
git checkout -b tmp1 branch1

# squash all history to one single commit
git reset --soft c1
git commit -m "branch1 content"

# replay that commit on top of c2 :
git checkout -b tmp2 c2
git cherry-pick tmp1

# you can now compare tmp2 and branch2 :
git diff tmp2 branch2
Related