Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git log --branches with multiple branches using glob patterns

I can't get git log --branches to do what I want. I want to output, in a single graph, commits matching these glob patterns:

  • users/userA/*
  • fix/*
  • master

I tried these approaches which don't work (they display commits from the current branch):

  • git log --branches="users/bertgp/* /users/sessid/* master"
  • git log --branches="users/bertgp/*|/users/sessid/*|master" (regex-like syntax)

Is this possible? It seems that glob patterns don't have an or syntax.

Why I want to do this

I am using Git Extensions as my visual git client and its branch filter box appends its content to a (single) --branches= option for its git log command.

I opened a Git Extensions feature request to support this.

like image 289
bernie Avatar asked Apr 24 '26 12:04

bernie


2 Answers

You can repeat the --branches option multiple times:

git log --branches="users/bertgp/*" --branches="/users/sessid/*"

In bash, it can be compressed, taking advantage of brace expansion, to

git log --branches={"users/bertgp/*","/users/sessid/*"}

However, most probably, neither of these answers to your original question will work with Git Extensions.

like image 79
Leon Avatar answered Apr 27 '26 02:04

Leon


This is possible in Git Extensions 2.49 (not check earlier versions). Though it is cumbersome...

Actually text from branch filter inserted into git command line as-is (or prefixed by --branches=) without escaping or somethig similar. Which means that you can add arbitrary git options.

Here is next things you should know:

  1. if branch filter contains globing symbols, then GitExt prefixed it with --branches=
  2. git does not accept more than one branch for log, so you should use --branches for every branch
  3. for remote branches should be used --remotes
  4. if used branch without globing, then git automatically add /* to end of branch, so you can't use --branches=master, instead you should use --branches=maste[r] with fake globing

Some examples:

  1. users/berniegp/* --branches=maste[r]

Should do what you asking for. It will be converted by GitExt to --branches=users/berniegp/* --branches=maste[r]

  1. users/berniegp/* --branches=maste[r] --remotes=origin/users/berniegp/*

Also show remote tracking branches (origin/users/berniegp/*)

  1. --reflog

Show also commits which references from reflog. May be useful for find 'lost' commits?

  1. --bisect

Should (I don't try it actually) show range of commits where problem was introduced (between good and bad)

  1. --reverse

Show commits in reverse order.

And other options of git log (https://git-scm.com/docs/git-log)

like image 44
Sergey Azarkevich Avatar answered Apr 27 '26 02:04

Sergey Azarkevich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!