2012-01-04 6 views
21

既存のコマンドか、 "ls"で表示されているファイルのステータスを表示できるトリックまたはスクリプトがありますか?どのようにしてgitのステータス情報を強化した "ls"?

$ git ls status #Command could be anything `lsg` is fine too, whatever. 

app   contents modified 
autotest  up-to-date 
config  up-to-date 
config.ru  staged 
db   contents modified 
doc   contents modified 
Gemfile  modified 
Gemfile.lock modified 
lib   up-to-date 
log   up-to-date 
public  up-to-date 
Rakefile  up-to-date 
README  up-to-date 
script  up-to-date 
spec   up-to-date 
tmp   up-to-date 
vendor  contents modidified 
test.tmp  removed 

:ディレクトリリストで利用可能gitのステータス情報を持つ次のような

何か。

+5

あなたは何を主張するだろうがのgit status' 'に対するこの形式の利点はありますか? – Nate

+1

@ネイト:それはより良いbirdseye、IMOを提供しています。多くのファイルが変更された場合は特に便利です。しかし、ディレクトリリスト全体のコンテキストの変化を見ることも有用です。 – berkes

+1

最も近いものはおそらく 'git status -s'ですが、変更以外のものは報告されません – fge

答えて

10

Gitステータスshort formatの情報を使用して、ここではAwkとcolumnコマンドを使用してステータス出力をカスタマイズするBashスクリプトを示します。

#!/bin/bash 
git status --porcelain | \ 
    awk 'BEGIN {FS=" "} 
{ 
    xstat = substr($0, 1, 1); 
    ystat = substr($0, 2, 1); 
    f = substr($0, 4); 
    ri = index(f, " -> "); 
    if (ri > 0) f = substr(f, 1, ri); 
    if (xstat == " " && ystat ~ "M|D") stat = "not updated"; 
    else if (xstat == "M" && ystat ~ " |M|D") stat = "updated in index"; 
    else if (xstat == "A" && ystat ~ " |M|D") stat = "added to index"; 
    else if (xstat == "D" && ystat ~ " |M") stat = "deleted from index"; 
    else if (xstat == "R" && ystat ~ " |M|D") stat = "renamed in index"; 
    else if (xstat == "C" && ystat ~ " |M|D") stat = "copied in index"; 
    else if (xstat ~ "M|A|R|C" && ystat == " ") stat = "index and work tree matches"; 
    else if (xstat ~ " |M|A|R|C" && ystat == "M") stat = "work tree changed since index"; 
    else if (xstat ~ " |M|A|R|C" && ystat == "D") stat = "deleted in work tree"; 
    else if (xstat == "D" && ystat == "D") stat = "unmerged, both deleted"; 
    else if (xstat == "A" && ystat == "U") stat = "unmerged, added by us"; 
    else if (xstat == "U" && ystat == "D") stat = "unmerged, deleted by them"; 
    else if (xstat == "U" && ystat == "A") stat = "unmerged, added by them"; 
    else if (xstat == "D" && ystat == "U") stat = "unmerged, deleted by us"; 
    else if (xstat == "A" && ystat == "A") stat = "unmerged, both added"; 
    else if (xstat == "U" && ystat == "U") stat = "unmerged, both modified"; 
    else if (xstat == "?" && ystat == "?") stat = "untracked"; 
    else if (xstat == "!" && ystat == "!") stat = "ignored"; 
    else stat = "unknown status"; 
    print f " " stat; 
}' | \ 
    column -t -s " " 

あなたは($HOME/binが良い場所でなければなりません)あなたのPATH上のディレクトリに実行可能git-status-lsを作成する場合は、任意のGitのレポでgit status-lsを入力することができます。あるいは、Gitエイリアスを1行作成することもできます。また、Perl、Python、Cなどの言語を使用して実装することもできます。ここで


は、サンプル出力です:ちょうど実現

B        renamed in index 
A        untracked 
dont_delete_git_pre-commit_hook untracked 

、タブはスペースとして表示されます。 Awkスクリプトprint f " " stat;column -t -s " "コマンドには、二重引用符の間にタブ(スペースではない)があります。タブ以外のセパレータを使用することもできます。


上記のスクリプトでステータスフラグの処理に問題があったことを認識し、修正しました。

+0

これは変更されていないファイルの "コンテキスト"を表示しません。しかし、私はこれで他のファイルもすべて追加することができると思います。 – berkes

+2

そのままですが、このスクリプトは、コミットできるかどうかのステータスを伝えます。変更されていない追跡されたファイルを一覧表示すると少しの作業が必要になります。私は迅速な解決策を見つけることができません。 –

-1

これはあなたが始める必要があります。

$ (git ls-files -o|sed -e 's/$/ untracked/'; \ 
    git ls-files -m|sed -e 's/$/contents modified/') | 
    sort 

を使用することができ、他のフラグのgit help ls-filesを参照してください。あなたは、出力あなたがあなたの例ではそれを持って道を揃えるprintfを組み込み、あなたのシェルを使用する場合があります

$ (git ls-files -o|sed -e 's/$/ untracked/'; \ 
git ls-files -m|sed -e 's/$/ contents modified/') | 
    sort | 
    while read file stat 
    do 
     printf "%-30s%-20s\n" $file $stat 
    done 
+0

git ls-filesを使ってディレクトリの内容だけをどのように報告するのか見当たりません。すべての再帰的情報を表示しない – berkes

関連する問題