Git equivalent for “hg log” with branch name check

Viewed 357

I would like to list down all commits directly done in a particular branch. In hg I'm able to get it using the below command.

hg log -b {branchname}

I've tried different command git to achieve the same but, nothing is useful.

git log --no-merges
git log --no-merges --first-parent
git log ---no-merge ^HEAD ^master
git log --branches={BRANCH}

How to list all changesets that are directly committed in a given branch but, not merges from other branches.

1 Answers

First of all, there is a fundamental difference between git and mercurial :

Mercurial has several kind of objects, among which : branches, and bookmarks.
git branches are like hg bookmarks, not like hg branches.

You will always only be able to see the history of the head commit of a git branch, not the actual sequence of intermediate states it went through.


It looks like you already tried the things that are close to "the history of a branch", I would have suggested :

git log --first-parent

git also keeps a log of how your local branch evolved through :

 git reflog <branchname>

but this log may be flushed if your branch was renamed at some point.

You can also have a partial view of how a remote branch evolved :

git reflog origin/<branchname>

this log is updated only when you fetch (or pull), so you may miss several intermediate steps if the branch was updated several times by other people between two fetch.


If you want to see commits on branch which are not part of master, try :

git log master..branch
# which is the same as :
git log ^master branch
Related