1

I've repository with hundreds of branches and I'd like to run git show only for these which have been recently fetched or updated as shown by git fetch, e.g.

$ git fetch tester
From repo:Foo/Bar
 * [new branch]      Foo -> origin/Foo
   a7e70a8..a9d7805  Bar -> origin/Bar
 + b673629...293dc64 Baz -> origin/Baz (forced update)
 + 345850e...b3646a3 Qux -> origin/Qux (forced update)

So I'd like to end up with the command like:

git show origin/Foo origin/Bar origin/Baz origin/Qux

which will show me the differences between these recent fetched branches and their parents commit(s).

How this can be achieved?


I've tried git show FETCH_HEAD, but it shows me only one branch along with the warning that refname 'FETCH_HEAD' is ambiguous.

And git show $(git branch -r --sort=authordate | head) shows me much older branches, secondly the command breaks on lines with ->, so it doesn't work either.

kenorb
  • 155,785
  • 88
  • 678
  • 743
  • Side note: `git show origin/Foo` does not show the difference between `origin/Foo` and `master` (except in one special case). It shows the difference between `origin/Foo` and its parent commit(s). If there is just one parent commit of `origin/Foo`, and that parent commit is also the commit named by `master`, then you get that one special case. (And, `git show ` shows each of the named commits in order, by the usual diff-commit-against-its-parent(s).) – torek Feb 01 '17 at 12:33
  • @torek Corrected that it's showing the differences between parent commit(s). – kenorb Feb 01 '17 at 12:38

2 Answers2

1

You can get the recently updated branches by using for-each-ref

git for-each-ref --sort=-committerdate refs/remotes/origin

Use --format=%(objectname) to get the heads of those branches. This get the five most recently updated branches,

git for-each-ref --sort=-committerdate --format="%(objectname)" refs/remotes/origin | head -5 
kenorb
  • 155,785
  • 88
  • 678
  • 743
pratZ
  • 3,078
  • 2
  • 20
  • 29
0

Here is the solution involving parsing of the git output, e.g.

git fetch tester 2>&1 | grep -o "origin/\S\+" | xargs git show

Replace origin with name of your remote host.

You can use --dry-run parameter to test it first (before fetching the branches), e.g.

git fetch tester --dry-run 2>&1 | grep -o "origin/\S\+"
kenorb
  • 155,785
  • 88
  • 678
  • 743