Dowemo
0 0 0 0


Question:

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?


Best Answer:


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



Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs