使用Git狀態short format信息,這是一個Bash腳本,它使用Awk和column
命令爲您提供自定義狀態輸出。
#!/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 " "
如果您創建一個目錄上您PATH
($HOME/bin
應該是一個不錯的地方)的可執行git-status-ls
,你可以在任何的Git回購型git status-ls
。或者你可以爲此創建一個Git別名。你也可以使用Perl,Python,C或任何你最喜歡的語言來實現它。
下面是一個示例輸出:
B renamed in index
A untracked
dont_delete_git_pre-commit_hook untracked
剛剛意識到,選項卡顯示爲空格。在Awk腳本print f " " stat;
和column -t -s " "
命令中,雙引號之間有一個製表符(不是空格)。您可以使用標籤以外的分隔符。
注意到上述腳本中的狀態標誌處理問題並進行了更正。
你會認爲這是格式通過'混帳status'的好處? – Nate 2012-01-04 12:42:33
@Nate:它提供了一個更好的birdseye,IMO。如果許多文件被改變,特別有用。但也要看到整個目錄列表的變化是有用的。 – berkes 2012-01-04 12:52:01
最接近的可能是'git status -s',但它不會報告除修改以外的其他內容 – fge 2012-01-04 13:09:23