27

I want to compare 2 branches using gitk, without the clutter of other branch histories.
I can achieve this via the gui: View > New view > Branches & tags: v0.8.x v0.9.x
I tried the following, but it still shows all branches: gitk --branches v0.8.x v0.9.x
What is the correct syntax?

robC
  • 2,592
  • 1
  • 23
  • 28

2 Answers2

35

gitk v0.8.x v0.9.x does it for me.

However, a closer look on the displayed branches shows me that there are actually not the given branches displayed. In addition, all branches that point to a commit in the history of the two branches are also shown.

So, the command displays all branches that are specified including those branches that are direct ancestors of the ones specified.


Edit:

The --branches= switch would be used if you want to see all branches that are, for example, named fix/*:

gitk --branches=fix/*

would show you all branches that are matching the given shell glob.

See also the docs of gitk for a deeper explanation.

eckes
  • 64,417
  • 29
  • 168
  • 201
  • Ah that's the desired result thank you. Do you know what the --branches option is for? – robC Jun 02 '14 at 11:13
  • 5
    Sadly I find this answer useless. It just doesn't work. I have no idea what those slash things in branch names are. I just have branch "master" (<- note no slashes) and branch "feature" (<- also note no slashes) and I want to see only those branches. No matter what I try giving to the `--branches` option, gitk will just say "No commits selected". What is the exact incantation I should use? – Szczepan Hołyszewski Oct 04 '18 at 10:45
  • 1
    @SzczepanHołyszewski it you only have `master` and `feature`, use `--all` to show all branches – eckes Oct 04 '18 at 11:09
  • Well, I misplaced "just" in my sentence. It should be in "I want" part, not in "I have" part. No, I don't "just" have those two branches. I have a few others, but I "just" want to see "just" these two in gitk. – Szczepan Hołyszewski Oct 04 '18 at 11:22
  • @SzczepanHołyszewski the docs say `limit refs to ones matching given shell glob`. So, if you can express the two branches to display using a glob pattern, you can use it as argument to `--branches`. If not, not. If they cannot be expressed using a glob pattern, stick to what OP describes: `View > New view > Branches & tags: master feature` – eckes Oct 04 '18 at 11:46
  • @eckes OK, I downgrade the specificity of my question: I strike the "using the `--branches` option" clause, and replace it with "by any means available". Is there *any* way to get gitk to display a subset of branches specified on the command line by exhaustive enumeration? – Szczepan Hołyszewski Oct 13 '18 at 21:32
  • @SzczepanHołyszewski Yes: `gitk master feature`, or `gitk origin/master master origin/feature feature` if you want to see the remote branches as well. Which of course could be shortened to `gitk {origin/,}{master,feature}` – Rikard Feb 07 '19 at 22:46
2

I was unable to get the --branches[=<pattern>] argument to work (for any shell glob, but especially for multiple globs). Fortunately, you can accomplish the same with a whole bunch of unix piping.

git branch -r | egrep "origin/(testing|prod|dev)" | xargs | tr '\n' ' ' | xargs -I {} bash -c 'gitk {}'

Breakdown:

  • git branch -r -- show all remote branches

  • egrep "origin/(testing|prod|dev)" -- filter to those that start with testing*, prod*, or dev*.

  • First xargs -- easy way to trim

  • tr '\n' ' ' -- combine all results into a single space-separated line

  • xargs -I {} bash -c 'gitk {}' -- pipe that line into gitk

MikeTwo
  • 1,228
  • 1
  • 14
  • 13
  • This is better than the accepted answer! `gitk --branches=...` has too many usability issues when you need something beyond `--branches=bugfix/*`. – Dmitry Avtonomov Jul 02 '21 at 16:54