Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does git log --branches work?

Tags:

git

I can't seem to get git log --branches to correctly filter its output. It seems as if Git ignores it.

For example, the head of git log --graph --all --decorate, prints:

* commit 3ae0d17538f787bdde68f37f6644ffe9652d8dc1 (HEAD, feature/branch-ignore) | Author: Chris Lewis <[email protected]> | Date:   Mon Mar 14 17:39:56 2011 -0700 |  |     Ignore merge commits, as they're going to be duplicating events |   * commit 770534e9d77acb03eaf842440c879aec1c5b5500 | Author: Chris Lewis <[email protected]> | Date:   Tue Mar 8 14:39:40 2011 -0800 |  |     Removed another remote branch check |  

Let's say I want to filter by master, which should mean these commits are ignored. The head of git log --graph --all --decorate --branches=master, is also:

* commit 3ae0d17538f787bdde68f37f6644ffe9652d8dc1 (HEAD, feature/branch-ignore) | Author: Chris Lewis <[email protected]> | Date:   Mon Mar 14 17:39:56 2011 -0700 |  |     Ignore merge commits, as they're going to be duplicating events |   * commit 770534e9d77acb03eaf842440c879aec1c5b5500 | Author: Chris Lewis <[email protected]> | Date:   Tue Mar 8 14:39:40 2011 -0800 |  |     Removed another remote branch check |   

Git doesn't seem to be filtering. It doesn't seem to make any difference whether --branches is passed with other arguments or not. My Git version is git version 1.7.4.1. Does anyone know how to use this command successfully?

EDIT: All I want to be able to do is get the log of one branch or another, without having to do a checkout first.

like image 459
cflewis Avatar asked Mar 15 '11 19:03

cflewis


People also ask

Does git log show all branches?

Graph all git branchesDevelopers can see all branches in the graph with the –all switch. Also, in most situations, the –decorate switch will provide all the supplemental information in a formatted and nicely color-coded way.

How does git keep track of branches?

Git stores all references under the . git/refs folder and branches are stored in the directory . git/refs/heads. Since branch is a simple text file we can just create a file with the contents of a commit hash.

What is the git log used for?

The git log command displays all of the commits in a repository's history. By default, the command displays each commit's: Secure Hash Algorithm (SHA) author.


1 Answers

Firstly, (the other) Adam is right that it doesn't make sense to use --all for this: if you only want to see one branch like your question states, why ask for all branches?

Secondly, as already stated in comments to other answers, you don't need --branches; just do git log mybranch.

Thirdly, I can explain why git log --branches=mybranch doesn't work. The git-log(1) man page says:

--branches[=<pattern>]     Pretend as if all the refs in refs/heads are listed on     the command line as <commit>. If <pattern> is given,      limit branches to ones matching given shell glob. If      pattern lacks ?, *, or [, /* at the end is implied. 

The last sentence is the crucial point here. If the <pattern> is just mybranch then there is no globbing character, so git-log interprets it as if you'd typed

git log --branches=mybranch/* 

which only matches references under $repo/.git/refs/heads/mybranch/*, i.e. branches which begin with mybranch/.

There is a dirty hack to prevent the /* from being assumed:

git log --branches=[m]ybranch 

but I can't think of any good reason why you would want to do this rather than just typing

git log mybranch 
like image 193
Adam Spiers Avatar answered Sep 21 '22 06:09

Adam Spiers