On Tue, 14 Jun 2016 03:47:45 -0700 (PDT)
Maheshwaran A N <avpalmah...@gmail.com> wrote:

> How to list all the commits done in a specific branch. As you all
> know, git log list the commits from all the branches (actual commits
> in that branch+ topic branches which got merged into).

No, the `git log` command works on the sets (in the mathematical sense)
of commits: it starts with the revisions you pass to it and traverses
the parts of the graph of commits reachable from those revisions.

I really recommend re-reading the "gitrevisions" manual page several
times and playing with the history in your repository.
Run `git help revisions` to get it.

As to your particular question, the first thing to note is that Git
records no "branch identity" in its commits, and taking into account
what I said above, your question has no sense and cannot be answered as

On the other hand, `git log` (actually the `git rev-list` plumbing
command which undelies it) has the "--first-parent" command-line option
which should provide a pretty close approximation of what you're after:
when chasing the subgraph of commits reachable from the tip of the
branch you supplied to it, it ignores all the parents of any merge
commit it sees except for the first one.  Since the first parent is
always the commit *into* which other lines of history have been merged
(to say it in other words, a commit which was checked out when someone
did the merge) the resulting commit traversal actually follows "the
mainline" of the history -- not displaying the chains of commits which
were merged into that mainline.

But beware of one quirk of this: in order for the "--first-parent" to do
what you need, your "topic branches" must always be merged into the
mainline, and not vice-versa (which -- textually, as long as the
project's content is concerned -- produces the same result) but has the
parents swapped into the resulting merge commit.

> Also, how to get the commits for a "particular file only in a
> specific branch"

First, all of the above applies to this case, too.

Second, `git log` et al accepts pathnames, so you can do something like

  $ git log mybranch -- a/path/to/that/file

where the "--" token is used to tell the Git's command-line parser that
the list of revisions and options is over, and what follows are

Beware though that Git does not track file renames, and if your file
got renamed somewhere down the history line the `git log` command won't
descend past that commit.  To make it guess where the rename (or
copy) has happened you might want to pass that command the "-M" and/or
"-C" command-line options; see the `git log` manual about the
"--find-renames", "--find-copies" and "--find-copies-harder"
command-line arguments.

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to