2016-05-14 9 views
1

私のチームは、ソースコントロールとしてgithubを使用してVisual Studioデータベースプロジェクトを処理します。私は次の情報で各ファイルの1行でレポートを生成したいと考えています:最後のエディタと日付でgithubリポジトリのすべてのファイルを一覧表示するにはどうすればよいですか?

  • filename;
  • 最後のアクション(追加、変更、または削除)。
  • 最後の編集者/コミット者の名前です。
  • 最終編集日/確定日。

どのコミットが関与しても構いません。私は、マスターブランチのファイルに最後に影響を与えたものを欲しがっています。

+0

これは 'git ls-tree --recursive'とその後の' git log'を使った処理を含む簡単なスクリプトでなければなりません。これまでに何を試しましたか? – user3159253

+0

@ user3159253、私はgit log/git showを--pretty = "%cn、%cd"で試しました。 - オンライン;および--name-status。寄稿者名と日付をファイル名とステータスで組み合わせるオプションを見つけることができないようです。これらのペアは排他的なようですか?私はgitbashに新しいです。 – Quicksilver

答えて

2
function report(){ 
    file=$1 
    #commit=$(git log -1 --pretty=%H -- "$file") 
    #Edit: use the following command instead, in order to deal with file paths with a space. 
    commit=$(git log -1 --pretty=%H -- "$file") 
    #if you want to ignore the files unchanged since the root commit, you could use: 
    #commit=$(git log -1 --pretty=%H --min-parents=1 -- "$file") 
    authorname=$(git log -1 $commit --pretty=%an) 
    commitdate=$(git log -1 $commit --pretty=%cd --date=short) 
    commitcomment=$(git log --format=%b -n 1 $commit) 
    status=$(git show $commit --pretty=%h --name-status | grep "$file" | awk '{print $1}') 
    case $status in 
    A) status=Added;; 
    C) status=Copied;; 
    D) status=Deleted;; 
    M) status=Modified;; 
    R) status=Renamed;; 
    T) status=Changed;; 
    U) status=Unmerged;; 
    B) status=Broken;; 
    *) status=Unknown;; 
    esac 
    echo "$commit|$file|$authorname|$commitdate|$status|$commitcomment" 
} 

#git ls-files | while read line; do report $line; done > report.txt 
#Edit:use the following command instead, in order to get all files, including deleted files. 
git log --pretty="/ %h" --name-only | grep -v ^$ | grep -v "/ " | sort -u | while read line;do report "$line"; done; > report.txt 

、その後、次の方法でフィールドをspliting、ExcelにREPORT.TXTをインポートすることができ '|'。

私のコードは十分に効率的ではないかもしれませんが、動作します。

+0

最初 - これは素晴らしいです。ありがとうございました!本当に印象的。私は2つの問題があると思う。 1つは、パスに空白があるとうまくいかないことです。残念ながら、Visual Studioでは「ストアドプロシージャ」などのフォルダの名前をいくつか指定しています。もう一つは、私はこれが削除を拾うとは思わないということですか?これはおそらく上記のls-tree -rを使用するための提案と組み合わせる必要があります。 – Quicksilver

+0

@Quicksilverあなたは歓迎され、とても助けになります。最初の問題については、 'commit = $(git log -1 --pretty =%H - $ file)'を 'commit = $(git log -1 --pretty =%H - " $ファイル ")'。そして、私は第2の問題にいくらか勉強します。 – ElpieKay

+0

@クイックシルバー第2の問題については、私は一時的な解決策を作り、 'git ls-files |一方、読取りライン。 $ lineを報告します。 'git log --pretty =" /%h "に' done> report.txt'を実行します--name-only | grep -v^$ | grep -v ^/|ソート-u |読み込み中は$ lineを報告します。完了しました。 > report.txt' – ElpieKay

関連する問題