Utilizzando lo stato Git short format, ecco uno script Bash che utilizza Awk e il comando column
per fornire output di stato personalizzato.
#!/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 " "
Se si crea un eseguibile git-status-ls
in una directory sul PATH
($HOME/bin
dovrebbe essere un buon posto), è possibile digitare git status-ls
in qualsiasi repo Git. Oppure potresti creare un one-liner Git alias per questo. Potresti anche implementarlo usando Perl, Python, C o qualsiasi altra lingua tu stia meglio.
Ecco un esempio di output:
B renamed in index
A untracked
dont_delete_git_pre-commit_hook untracked
appena realizzato, le schede sono la visualizzazione come spazi. Nello script Awk print f " " stat;
e nel comando column -t -s " "
, c'è una scheda (non spazi) tra le virgolette. È possibile utilizzare un separatore diverso da tab.
Notato un problema con i flag di stato che gestiscono nello script precedente e corretto.
fonte
2012-01-04 14:10:38
Cosa vorresti discutere è il vantaggio di questo formato su 'git status'? – Nate
@Nate: offre un birdseye migliore, IMO. Particolarmente utile se molti file sono stati modificati. Ma anche vedere le modifiche nel contesto dell'intera directory-dir è utile. – berkes
Il più vicino è probabilmente 'git status -s', ma non riporta altro che le modifiche – fge