8

My repository history looks something like this:

         x---y-+-z-+-branch
        /     /   /
---a---b---c-+-d-+-e---master

I want to get a single diff (i.e., like 'git diff' outputs- I don't want a whole bunch of diffs like 'git log -p' produces) of the complete history of 'branch', without including any of the changes that were merged into 'branch' from 'master'.

How can I do this?

spiffytech
  • 6,161
  • 7
  • 41
  • 57
  • not a real answer but maybe a direction: I don't think it is possible only with git tools. You could do some crazy shell hacking to do this. A good starting point: Show all commit shas which are only in your branch: `git log branch_name --not master --no-merges --pretty="format:%H"` – ben Mar 12 '13 at 22:45

1 Answers1

7

The command you are looking for is:

git diff master...branch

From git help diff:

git diff [--options] <commit>...<commit>

This form is to view the changes on the branch containing and up to the second

Chronial
  • 66,706
  • 14
  • 93
  • 99
  • 1
    "...starting at a common ancestor of both " - does that mean it's only going to provide me a diff of the changes since the last time I merged 'master' into 'branch', and not the entire history of 'branch'? – spiffytech Mar 13 '13 at 14:46
  • have you tried the command? it will diff `d` against `branch` in your drawing. That will show all the changes that only happened on branch, since you created it (`b`). – Chronial Mar 13 '13 at 22:16
  • Indeed, this command does show what I need. I'm not clear why, though, given the above snippet from the command's help section. – spiffytech Mar 22 '13 at 13:19
  • What exactly is confusing you? Or describe what you think this command does / should do (based on your understanding). – Chronial Mar 27 '13 at 16:01
  • 1
    As the docs say the command shows a diff from the common ancestor, given the above graph, I expected the diff to only show changes since the last time I merged `master` into `branch`, since all commits on `master` prior to that would be common to `branch`. Here, that would be an empty diff. Typing this out (yay rubber duck programming!), I now realize the command works because although `master`'s commits are now on `branch`, `branch`'s commits aren't on `master`. If I first merged `branch` into `master', then vise versa, *that* should be the new common ancestor from which the diff starts, yes? – spiffytech Mar 27 '13 at 21:38
  • Yes, I think you got it. It is important to remember, that a git commit is not a change, but a state of your whole tree. So if git diffs two commits, it does not care what was changed when, but only what the difference is. If you merge `branch` into `master` and then merge `master` into `branch`, a diff of these branches will indeed be empty, since they will be the same. The common ancestor would be the merge of `branch` into `master`. – Chronial Mar 28 '13 at 19:39
  • But I don't. According to the doc: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B". Wouldn't `git merge-base master branch` yield the hash for commit `d`? And then `git diff d branch` show... mmm. `z`, not `c` since it is both in the history of `d` and `branch`, `y`, and `x`. Which is... correct. Rubber duck \o/. Yes? – Gauthier Apr 10 '14 at 07:50