1

How to do diff between branches to get what the Merge diff will look like

consider this graph

*   master
|\
| * b1
|\ 
| * b2

if im on b2, and the person on b1 beat me and merged into master,

if i do

project>b2 $ git diff origin/master

the diff would include b1, which would not be included in the PR, how do I reproduce this in command line.

user2167582
  • 5,429
  • 12
  • 54
  • 104
  • Possible duplicate of [How can I preview a merge in git?](http://stackoverflow.com/questions/5817579/how-can-i-preview-a-merge-in-git) – max630 Nov 20 '16 at 16:57

2 Answers2

1

I believe that git merge-tree will do it. It doesn't perform a merge but instead outputs a diff which represents the merge.

It takes three arguments: git merge-tree <base-tree> <branch1> <branch2>

I find it easier to read when piping its output into colordiff and then a pager. (I use less with -r to handle the colors.)

git merge-tree $(git merge-base HEAD b2) HEAD b2 | colordiff | less -r
JellicleCat
  • 26,352
  • 22
  • 102
  • 152
0

You can update origin/master with git fetch origin. This will update your remote branches without changing anything else.

After that, you can rebase your b2 work onto origin/master with git rebase origin/master. Now b2 will be based on the latest work including b1. Then git diff origin/master will reflect the addition of b1.

Then you can update the PR with git push --force.

Schwern
  • 139,746
  • 23
  • 170
  • 313
  • that sounds very practical and straight forward, and it sounds like you have posed or have been posed to this problem. But is there a command i can do that grants that for me? and what if i want to get a preview without actually changing content on any branch. I dont htink it would take a lot of work right, all we need to check is for commits unknown to the master branchs and merge those commits. – user2167582 Nov 18 '16 at 17:58
  • @user2167582 You don't have to do the rebase. Just `git fetch origin` to get the updated `origin/master` and then diff. But if your purpose is to submit `b2` as a pull request, you should update it on top of the latest `origin/master` (ie. rebase) and make sure it still works. – Schwern Nov 18 '16 at 21:28