19

A colleague created a local branch ('branchA') from master, did some work, pushed it, merged in master, did some more work and pushed it again. Concurrently, other colleagues have been working on other branches and merging them to master.

Now I need to pull branchA to review it. So I've done a git pull and git checkout -b branchA origin/branchA which is fine. But all of the commands (git diff/log/show) show commits made across all branches in the repo.

How can I view a diff of all of the commits made to branchA against the version of master that it was created from?

Also how can I git diff branchA against the current HEAD of master, but only view files changed within branchA?

user1491250
  • 1,831
  • 4
  • 18
  • 21

5 Answers5

21

The following applies to your second question, how to find the differences between branchA and your local's current version of master. You want to use 'double dot' syntax with git log to see all the commits in branchA that aren't in master. To wit:

git log master..branchA

Per the git log man page:

SYNOPSIS
   git log [<options>] [<since>..<until>] [[--] <path>...]
   ...
   <since>..<until>
   Show only commits between the named two commits. When either <since> or <until> is omitted, it defaults to HEAD, i.e. the tip of the current branch.
   For a more complete list of ways to spell <since> and <until>, see gitrevisions(7).

If you'd like to see commits in either master or branchA, but not in both, you can use 'triple-dot' syntax:

git log master...branchA

Finally, you can use the exact same syntax with git diff, namely, git diff master..branchA and git diff master...branchA, respectively.

As an aside, if you have branchA checked out, you don't even need to specify it as <until>. Git will assume HEAD if it's left unspecified, so these two sets of commands are equivalent:

git checkout branchA
git log master..

and

git log master..branchA
Christopher
  • 42,720
  • 11
  • 81
  • 99
4
  1. git diff master..brnachA: will compare all modified files between HEAD of master and branchA.
  2. git diff master...brnachA: will compare branchA against the version of master that it was created from.

FYI: git diff will generate output in command line. If you want to see the output in some visual tools, use git difftool.

You can pass all git diff arguments and options to git difftool as well.

Karthik Bose
  • 33,556
  • 3
  • 33
  • 43
  • -2- is not quite right. It'll return commits in either `master` or `branchA` but not both. If `master` advanced 50 commits, but `branchA` was fully merged, it'll return the 50 commits in master. That doesn't compare `branchA` against its merge base in master, which appears to be the first question? – Christopher Aug 01 '12 at 11:30
2

Git commits don't retain information about "which branch" they were committed on. They only give you a point in the tree you can walk back from. Once a merge happens, you have no way, from a merge commit, to decide which parent came from the branch you started from. This is discussed in some details over here.

This is my understanding. I'd love to be corrected if I'm wrong.

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
0

you can use git log --branches=mybranch

This will show log on specific branch

forvaidya
  • 3,041
  • 3
  • 26
  • 33
0

git log HEAD..branch when you are on the master branch.

Look here for more detail: How to get the changes on a branch in git

Community
  • 1
  • 1
clearwater82
  • 1,746
  • 14
  • 9