Home > Enterprise >  How to show changed file list by a specific author in a Git repository?
How to show changed file list by a specific author in a Git repository?

Time:04-12

How to show changed files by a specific author in a Git repository?

When I use this command git log --numstat --pretty=tformat:'%an',

git bash will group files by the author, like this:

WoJiaoChaDi-YSS
16      6       AHKScriptManager/scripts/AutoInput/HotKeyString.ini
1       1       AHKScriptManager/scripts/RemindMe/RemindConfig.ini
21      0       OneQuick.Ext.ahk

WoJiaoChaDi-PC
1       1       AHKScriptManager/scripts/AutoCapture/config.ini

but I want to get result like this: (author in every line head posistion)

WoJiaoChaDi-YSS      16      6       AHKScriptManager/scripts/AutoInput/HotKeyString.ini
WoJiaoChaDi-YSS      1       1       AHKScriptManager/scripts/RemindMe/RemindConfig.ini
WoJiaoChaDi-YSS      21      0       OneQuick.Ext.ahk

WoJiaoChaDi-PC       1       1       AHKScriptManager/scripts/AutoCapture/config.ini

so, who can help me?

CodePudding user response:

It could be done with some bash scripting:

#!/bin/bash

git log --pretty=tformat:'%H;%an' | while IFS=';' read COMMIT AUTHOR; do
  git log --max-count=1 --numstat --pretty=tformat:'' "$COMMIT" | sed "s/^\(.\)/$AUTHOR\t\1/"
  printf "\n"
done

CodePudding user response:

Thanks for providing way for this question, user14967413 brother.

And I have an other way to do that, like this:

git log --numstat --pretty=format:'%an' | awk '{x=$1; 
    if(x!~/[0-9] |-/){
        name=$1
    } else {
        print name, $0
    }
}'

It is harvest that I have learned awk syntax for 2 hours.

  • Related