Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: How to view commits to a single branch

Tags:

git

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?

like image 644
user1491250 Avatar asked Aug 01 '12 10:08

user1491250


People also ask

How can you view all the commits for a single file?

Use git log --all <filename> to view the commits influencing <filename> in all branches.

How do I see commits in master branch?

To confirm, you can run git branch . The branch that you are on will be the one with a * next to it. Git checkout might fail with an error message, e.g. if it would overwrite modified files. Git branch should show you the current branch and git log master allows you to view commit logs without changing the branch.

How can I see commits in git?

The most basic and powerful tool to do this is the git log command. By default, with no arguments, git log lists the commits made in that repository in reverse chronological order; that is, the most recent commits show up first.


2 Answers

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
like image 155
Christopher Avatar answered Sep 18 '22 14:09

Christopher


  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.

like image 30
Karthik Bose Avatar answered Sep 20 '22 14:09

Karthik Bose