Show last commit on each remote branch by source using `git for-each-ref` and` git log`

Having done git fetch --all --pruneto extract links from remote repositories, I now want to see the most recent commit on each branch onorigin

Team

git for-each-ref --format='%(refname:short)' | grep 'origin/'

displays all sixteen branches on origin, and so I expect the following command to show the most recent commit from each

git for-each-ref --format='%(refname:short)' | grep 'origin/' | 
xargs git log --source -n 1 

(NB This is one line, when I run it, I split it into two for readability.)

However, the command does not work, it lists only one commit: it seems that one commit restriction applies to the entire list, and not to each branch in turn.

What am I doing wrong?

(Note that I also tried to adapt the solution here

git for-each-ref --format='%(refname:short)' | grep 'origin/' | 
xargs git show --oneline 

--oneline , .)

+4
3

, git ref, xargs . , , git log -n 1 origin/master origin/not_master ( xargs ), , . , , , .

VonC , git xargs:

for ref in $(git for-each-ref --format='%(refname:short)' | grep 'origin/')
do
    git --no-pager log $ref -n 1 --oneline
done

-no-pager .

+3

git ls-remote origin:

git ls-remote --heads origin

, git repo:

C:\Users\vonc\prog\git\git>git ls-remote --heads origin|
117eea7eaaeb5ecb77d9b7cebdb40b4e85f37374        refs/heads/maint
f5b6079871904ba5b0a8548f91545f126caf898b        refs/heads/master
edb03e5a9b9b63d0864557f99f339b2b5f3a9e4e        refs/heads/next
014438bc5bdf9deef0d3888e58c9f76addc1106c        refs/heads/pu
56f24e80f0af4dd3591c8f143183b59cf9a34620        refs/heads/tmp
33f854ca9eb8251f5b7fa1c670d4abcdd76764ce        refs/heads/todo

... !

:

C:\Users\vonc\prog\git\git>
git config alias.rh "!git ls-remote -h origin | while read b; do PAGER='' git log -n1 --color --pretty=format:'%ct%C(yellow)%d%Creset - %Cred%h%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset%n' --abbrev-commit $( echo $b | cut -d' ' -f1 ) --; done | sort -rn -k1,10 | cut -c11-"

git rh :

C:\Users\vonc\prog\git\git>git rh
 (origin/master, origin/HEAD) - f5b6079 Second batch for 2.7 (3 months ago) <Junio C Hamano>
 (origin/next, next) - edb03e5 Sync with 2.1-rc2 (1 year, 5 months ago) <Junio C Hamano>
 (origin/tmp, tmp) - 56f24e8 completion: handle '!f() { ... }; f' and "!sh -c '...' -" aliases (1 year, 7 months ago) <Steffen Prohaska>
 (origin/pu) - 014438b Merge branch 'nd/multiple-work-trees' into pu (1 year, 10 months ago) <Junio C Hamano>
 (origin/todo) - 33f854c What cooking (2013/07 #09) (2 years, 5 months ago) <Junio C Hamano>
 (tag: v1.8.3.4, origin/maint) - 117eea7 Git 1.8.3.4 (2 years, 6 months ago) <Junio C Hamano>

:

git rh


, 'origin'.

, :

C:\Users\vonc\prog\git\git>git config alias.rh "!f() { git ls-remote -h $1 | while read b; do PAGER='' git log -n1 --pretty=format:'%h%n' --abbrev-commit $( echo $b | cut -d' ' -f1 ) --; done; }; f"
                                                                        ^^

:

C:\Users\vonc\prog\git\git>git rh upstream
833e482
7548842
ef7b32d
f67e31e
e2281f4
+4

Andrew C , git ( grep), andreas-hofmann ( ), xargs , -

git for-each-ref --format='%(refname:short)' refs/remotes/origin/ | xargs -n1 git log --max-count=1 --source

This swaps the pattern match in the git command and tells xargs to provide at most one argument at a time.

(NB Matching the pattern in the git for-each-ref command comes from the start of the match, so I need to use 'refs / remotes / origin /' instead of the pattern 'origin /' that I could use with grep. And I could replace - -max-count = 1 s -1 for short.)

+2
source

Source: https://habr.com/ru/post/1623641/


All Articles