增强型;ls";有git状态信息吗?
是否存在允许我显示“ls”中显示的文件状态的现有命令或某些技巧或脚本 如下所示:增强型;ls";有git状态信息吗?,git,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 d
$ 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状态信息。使用git状态信息,下面是一个Bash脚本,它使用Awk和列
命令为您提供定制的状态输出
#!/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 " "
如果您在路径
上的目录中创建了一个可执行的git status ls
($HOME/bin
应该是个好地方),您可以在任何git repo中键入git status ls
。或者您可以为此创建Git alias one liner。您还可以使用Perl、Python、C或任何您最熟悉的语言来实现它
以下是一个示例输出:
B renamed in index
A untracked
dont_delete_git_pre-commit_hook untracked
刚刚意识到,选项卡显示为空格。在Awk脚本
print f“stat中
并且在列-t-s”“
命令中,双引号之间有一个制表符(不是空格)。可以使用制表符以外的分隔符
注意到上面脚本中的状态标志处理问题,并进行了更正。这应该可以让您开始:
$ ( git ls-files -o|sed -e 's/$/ untracked/'; \
git ls-files -m|sed -e 's/$/contents modified/') |
sort
有关可以使用的其他标志,请参见git help ls files
您可能希望使用shell内置的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
K
具有git功能的zsh目录列表
我想要这样的东西——用git的状态注释常规的
ls
输出。我非常喜欢在另一个回答中提到的k
命令,但它是特定于zsh的。因此,我编写了一个bash脚本,它可以放在我的库中,从我使用的任何shell运行,它修改了ls
的输出,以添加来自git的额外信息
由于它修改了ls
的输出,因此您可以使用任何[1]个ls
开关运行它,它将修改输出以包含git信息。它没有完全使用问题中要求的描述,但它确实描述了文件、存储库和子模块的更改状态
例如:
charles@laputa ~/projects/prm (add-ci-build-support)> lsg
Makefile {ignored}
artifacts {ignored}
build-to-junitxml.yaml {untracked}
catalog
ci (replace-bash-junit-xml-processor↓4 19 forward) {1 modified}
ci-logs {ignored}
do-build.sh
index-makefile-ro.xsl
index-makefile.xsl
index.xml
index.xsl {modified locally, 3 lines}
logs {ignored}
old-header {untracked}
output {ignored}
project.config
src
test-results.xml {untracked}
tmp {ignored}
在上述情况下:
- 有许多被忽略的文件(
以灰色显示){ignored}
- 有一些未跟踪(
显示为红色){untracked}
- 一个文件更改了三行(
显示为黄色,表示已修改){modified local,3行}
备注是关于文件或目录的{}
备注是关于存储库的()
- 一个目录,
是一个存储库:ci
- 当前在分支头后面有4个提交
(分支名称用青色表示,后面的更改数用蓝色表示)替换bash junit xml处理器
- 比上次提交时提前19个更改(
为黄色,表示已修改)19 forward
- 其中包含1个已修改的文件(
为黄色,表示已修改)1个已修改的
- 当前在分支头后面有4个提交
git status
中使用的git配置中读取的
[1] 有些开关没有意义-它强制每个文件1行,不支持dired模式或其他一些格式。你认为这种格式比git status有什么好处?@Nate:它提供了更好的birdseye,IMO。特别是在许多文件被更改时更有用。但是也可以查看整个目录列表上下文中的更改。最接近的可能是
git status-s
,但它不会报告除修改以外的任何内容-uno
,以忽略未跟踪文件的输出。这不会显示未更改文件的“上下文”。但我想我也可以从这个开始添加所有其他文件。照目前的情况,这个脚本只会告诉您将/可能提交的内容的状态。列出未修改的跟踪文件似乎需要一些工作;我找不到快速的解决方案。我看不出git ls文件如何仅用于报告目录内容;i、 e.不要显示所有递归信息